FixerNameValidatorTest.php 1.8 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788
  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. public static function provideIsValidCases(): iterable
  32. {
  33. yield ['', true, false];
  34. yield ['', false, false];
  35. yield ['foo', true, false];
  36. yield ['foo', false, true];
  37. yield ['foo_bar', false, true];
  38. yield ['foo_bar_4', false, true];
  39. yield ['Foo', false, false];
  40. yield ['fooBar', false, false];
  41. yield ['4foo', false, false];
  42. yield ['_foo', false, false];
  43. yield ['4_foo', false, false];
  44. yield ['vendor/foo', false, false];
  45. yield ['bendor/foo', true, false];
  46. yield ['Vendor/foo', true, true];
  47. yield ['Vendor4/foo', true, true];
  48. yield ['4vendor/foo', true, false];
  49. yield ['Vendor/foo', true, true];
  50. yield ['FooBar/foo', true, true];
  51. yield ['Foo-Bar/foo', true, false];
  52. yield ['Foo_Bar/foo', true, false];
  53. yield ['Foo/foo/bar', true, false];
  54. yield ['/foo', true, false];
  55. yield ['/foo', false, false];
  56. yield ['/foo/bar', true, false];
  57. }
  58. }