Skip to content

Commit

Permalink
trivial test to ensure command does not crash
Browse files Browse the repository at this point in the history
  • Loading branch information
keradus committed Apr 18, 2021
1 parent c3e219b commit c2edbd5
Show file tree
Hide file tree
Showing 3 changed files with 69 additions and 3 deletions.
3 changes: 0 additions & 3 deletions src/Console/Command/ListSetsCommand.php
Expand Up @@ -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;
Expand Down
1 change: 1 addition & 0 deletions tests/Console/Command/ListFilesCommandTest.php
Expand Up @@ -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());
}

Expand Down
68 changes: 68 additions & 0 deletions tests/Console/Command/ListSetsCommandTest.php
@@ -0,0 +1,68 @@
<?php

/*
* This file is part of PHP CS Fixer.
*
* (c) Fabien Potencier <fabien@symfony.com>
* Dariusz Rumiński <dariusz.ruminski@gmail.com>
*
* 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;
}
}

0 comments on commit c2edbd5

Please sign in to comment.