ListSetsCommandTest.php 1.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869
  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\Console\Command;
  13. use PhpCsFixer\Console\Application;
  14. use PhpCsFixer\Console\Command\ListSetsCommand;
  15. use PhpCsFixer\Tests\TestCase;
  16. use Symfony\Component\Console\Tester\CommandTester;
  17. /**
  18. * @internal
  19. *
  20. * @covers \PhpCsFixer\Console\Command\ListSetsCommand
  21. */
  22. final class ListSetsCommandTest extends TestCase
  23. {
  24. public function testListWithTxtFormat(): void
  25. {
  26. $commandTester = $this->doTestExecute([
  27. '--format' => 'txt',
  28. ]);
  29. $resultRaw = $commandTester->getDisplay();
  30. $expectedResultStart = ' 1) @DoctrineAnnotation'.PHP_EOL.' Rules covering Doctrine annotations';
  31. self::assertStringStartsWith($expectedResultStart, $resultRaw);
  32. self::assertSame(0, $commandTester->getStatusCode());
  33. }
  34. public function testListWithJsonFormat(): void
  35. {
  36. $commandTester = $this->doTestExecute([
  37. '--format' => 'json',
  38. ]);
  39. $resultRaw = $commandTester->getDisplay();
  40. self::assertJson($resultRaw);
  41. self::assertSame(0, $commandTester->getStatusCode());
  42. }
  43. /**
  44. * @param array<string, bool|string> $arguments
  45. */
  46. private function doTestExecute(array $arguments): CommandTester
  47. {
  48. $application = new Application();
  49. $application->add(new ListSetsCommand());
  50. $command = $application->find('list-sets');
  51. $commandTester = new CommandTester($command);
  52. $commandTester->execute($arguments);
  53. return $commandTester;
  54. }
  55. }