From c2edbd511d67aaaa51a5ffbf30e08d7e5e5f3eef Mon Sep 17 00:00:00 2001 From: Dariusz Ruminski Date: Sun, 18 Apr 2021 17:09:40 +0200 Subject: [PATCH] trivial test to ensure command does not crash --- src/Console/Command/ListSetsCommand.php | 3 - .../Console/Command/ListFilesCommandTest.php | 1 + tests/Console/Command/ListSetsCommandTest.php | 68 +++++++++++++++++++ 3 files changed, 69 insertions(+), 3 deletions(-) create mode 100644 tests/Console/Command/ListSetsCommandTest.php diff --git a/src/Console/Command/ListSetsCommand.php b/src/Console/Command/ListSetsCommand.php index 5695cbcc49b..a2d3223e11c 100644 --- a/src/Console/Command/ListSetsCommand.php +++ b/src/Console/Command/ListSetsCommand.php @@ -12,14 +12,11 @@ namespace PhpCsFixer\Console\Command; -use PhpCsFixer\Config; -use PhpCsFixer\ConfigInterface; use PhpCsFixer\ConfigurationException\InvalidConfigurationException; use PhpCsFixer\Console\Report\ListSetsReport\ReporterFactory; use PhpCsFixer\Console\Report\ListSetsReport\ReportSummary; use PhpCsFixer\Console\Report\ListSetsReport\TextReporter; use PhpCsFixer\RuleSet\RuleSets; -use PhpCsFixer\ToolInfoInterface; use Symfony\Component\Console\Command\Command; use Symfony\Component\Console\Formatter\OutputFormatter; use Symfony\Component\Console\Input\InputInterface; diff --git a/tests/Console/Command/ListFilesCommandTest.php b/tests/Console/Command/ListFilesCommandTest.php index 3b7f713949f..c1308c6167e 100644 --- a/tests/Console/Command/ListFilesCommandTest.php +++ b/tests/Console/Command/ListFilesCommandTest.php @@ -35,6 +35,7 @@ public function testListWithConfig() // make the test also work on windows $expectedPath = str_replace('/', \DIRECTORY_SEPARATOR, $expectedPath); + static::assertSame(0, $commandTester->getStatusCode()); static::assertSame(escapeshellarg($expectedPath).PHP_EOL, $commandTester->getDisplay()); } diff --git a/tests/Console/Command/ListSetsCommandTest.php b/tests/Console/Command/ListSetsCommandTest.php new file mode 100644 index 00000000000..4e0db869501 --- /dev/null +++ b/tests/Console/Command/ListSetsCommandTest.php @@ -0,0 +1,68 @@ + + * Dariusz RumiƄski + * + * This source file is subject to the MIT license that is bundled + * with this source code in the file LICENSE. + */ + +namespace PhpCsFixer\Tests\Console\Command; + +use PhpCsFixer\Console\Application; +use PhpCsFixer\Console\Command\ListSetsCommand; +use PhpCsFixer\Tests\TestCase; +use PhpCsFixer\ToolInfo; +use Symfony\Component\Console\Tester\CommandTester; + +/** + * @internal + * + * @covers \PhpCsFixer\Console\Command\ListSetsCommand + */ +final class ListSetsCommandTest extends TestCase +{ + public function testListWithTxtFormat() + { + $commandTester = $this->doTestExecute([ + '--format' => 'txt', + ]); + + $resultText = $commandTester->getDisplay(); + $expectedResultStart = ' 1) @DoctrineAnnotation + Rules covering Doctrine annotations'; + static::assertStringStartsWith($expectedResultStart, $resultText); + static::assertSame(0, $commandTester->getStatusCode()); + } + + public function testListWithJsonFormat() + { + $commandTester = $this->doTestExecute([ + '--format' => 'json', + ]); + + $resultText = $commandTester->getDisplay(); + + static::assertJson($resultText); + static::assertSame(0, $commandTester->getStatusCode()); + } + + /** + * @return CommandTester + */ + private function doTestExecute(array $arguments) + { + $application = new Application(); + $application->add(new ListSetsCommand()); + + $command = $application->find('list-sets'); + $commandTester = new CommandTester($command); + + $commandTester->execute($arguments); + + return $commandTester; + } +}