FixerNameValidatorTest.php 1.9 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889
  1. <?php
  2. declare(strict_types=1);
  3. /*
  4. * This file is part of PHP CS Fixer.
  5. *
  6. * (c) Fabien Potencier <fabien@symfony.com>
  7. * Dariusz Rumiński <dariusz.ruminski@gmail.com>
  8. *
  9. * This source file is subject to the MIT license that is bundled
  10. * with this source code in the file LICENSE.
  11. */
  12. namespace PhpCsFixer\Tests;
  13. use PhpCsFixer\FixerNameValidator;
  14. /**
  15. * @author Dariusz Rumiński <dariusz.ruminski@gmail.com>
  16. *
  17. * @internal
  18. *
  19. * @covers \PhpCsFixer\FixerNameValidator
  20. */
  21. final class FixerNameValidatorTest extends TestCase
  22. {
  23. /**
  24. * @dataProvider provideIsValidCases
  25. */
  26. public function testIsValid(string $name, bool $isCustom, bool $isValid): void
  27. {
  28. $validator = new FixerNameValidator();
  29. self::assertSame($isValid, $validator->isValid($name, $isCustom));
  30. }
  31. /**
  32. * @return iterable<array{string, bool, bool}>
  33. */
  34. public static function provideIsValidCases(): iterable
  35. {
  36. yield ['', true, false];
  37. yield ['', false, false];
  38. yield ['foo', true, false];
  39. yield ['foo', false, true];
  40. yield ['foo_bar', false, true];
  41. yield ['foo_bar_4', false, true];
  42. yield ['Foo', false, false];
  43. yield ['fooBar', false, false];
  44. yield ['4foo', false, false];
  45. yield ['_foo', false, false];
  46. yield ['4_foo', false, false];
  47. yield ['vendor/foo', false, false];
  48. yield ['bendor/foo', true, false];
  49. yield ['Vendor/foo', true, true];
  50. yield ['Vendor4/foo', true, true];
  51. yield ['4vendor/foo', true, false];
  52. yield ['FooBar/foo', true, true];
  53. yield ['Foo-Bar/foo', true, false];
  54. yield ['Foo_Bar/foo', true, false];
  55. yield ['Foo/foo/bar', true, false];
  56. yield ['/foo', true, false];
  57. yield ['/foo', false, false];
  58. yield ['/foo/bar', true, false];
  59. }
  60. }