DescribeCommandTest.php 2.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990
  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\Console\Command\DescribeCommand;
  15. use PhpCsFixer\Fixer\DeprecatedFixerInterface;
  16. use PhpCsFixer\Fixer\Internal\ConfigurableFixerTemplateFixer;
  17. use PhpCsFixer\FixerFactory;
  18. use PhpCsFixer\Tests\TestCase;
  19. use PhpCsFixer\Utils;
  20. use Symfony\Component\Console\Tester\CommandTester;
  21. /**
  22. * @internal
  23. *
  24. * @coversNothing
  25. *
  26. * @group legacy
  27. * @group auto-review
  28. * @group covers-nothing
  29. */
  30. final class DescribeCommandTest extends TestCase
  31. {
  32. /**
  33. * @dataProvider provideDescribeCommandCases
  34. *
  35. * @param list<string> $successorsNames
  36. */
  37. public function testDescribeCommand(string $fixerName, ?array $successorsNames): void
  38. {
  39. if (null !== $successorsNames) {
  40. $message = "Rule \"{$fixerName}\" is deprecated. "
  41. .([] === $successorsNames
  42. ? 'It will be removed in version 4.0.'
  43. : \sprintf('Use %s instead.', Utils::naturalLanguageJoin($successorsNames)));
  44. $this->expectDeprecation($message);
  45. }
  46. // @TODO 4.0 Remove this expectations
  47. $this->expectDeprecation('Rule set "@PER" is deprecated. Use "@PER-CS" instead.');
  48. $this->expectDeprecation('Rule set "@PER:risky" is deprecated. Use "@PER-CS:risky" instead.');
  49. if ('nullable_type_declaration_for_default_null_value' === $fixerName) {
  50. $this->expectDeprecation('Option "use_nullable_type_declaration" for rule "nullable_type_declaration_for_default_null_value" is deprecated and will be removed in version 4.0. Behaviour will follow default one.');
  51. }
  52. $command = new DescribeCommand();
  53. $application = new Application();
  54. $application->add($command);
  55. $commandTester = new CommandTester($command);
  56. $commandTester->execute([
  57. 'command' => $command->getName(),
  58. 'name' => $fixerName,
  59. ]);
  60. self::assertSame(0, $commandTester->getStatusCode());
  61. }
  62. public static function provideDescribeCommandCases(): iterable
  63. {
  64. yield [
  65. (new ConfigurableFixerTemplateFixer())->getName(),
  66. null,
  67. ];
  68. $factory = new FixerFactory();
  69. $factory->registerBuiltInFixers();
  70. foreach ($factory->getFixers() as $fixer) {
  71. yield [
  72. $fixer->getName(),
  73. $fixer instanceof DeprecatedFixerInterface ? $fixer->getSuccessorsNames() : null,
  74. ];
  75. }
  76. }
  77. }