CommandTest.php 1.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657
  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\AutoReview;
  13. use PhpCsFixer\Console\Application;
  14. use PhpCsFixer\Tests\TestCase;
  15. use Symfony\Component\Console\Command\Command;
  16. /**
  17. * @author Dariusz Rumiński <dariusz.ruminski@gmail.com>
  18. *
  19. * @internal
  20. *
  21. * @coversNothing
  22. *
  23. * @group auto-review
  24. * @group covers-nothing
  25. */
  26. final class CommandTest extends TestCase
  27. {
  28. /**
  29. * @dataProvider provideCommandHasNameConstCases
  30. */
  31. public function testCommandHasNameConst(Command $command): void
  32. {
  33. self::assertNotNull($command::getDefaultName());
  34. }
  35. /**
  36. * @return iterable<array{Command}>
  37. */
  38. public static function provideCommandHasNameConstCases(): iterable
  39. {
  40. $application = new Application();
  41. $commands = $application->all();
  42. $names = array_filter(
  43. array_keys($commands),
  44. // is not an alias and is our command
  45. static fn (string $name): bool => !\in_array($name, $commands[$name]->getAliases(), true) && str_starts_with(\get_class($commands[$name]), 'PhpCsFixer\\')
  46. );
  47. return array_map(static fn (string $name): array => [$commands[$name]], $names);
  48. }
  49. }