ListFilesCommandTest.php 1.6 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556
  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\ListFilesCommand;
  15. use PhpCsFixer\Tests\TestCase;
  16. use PhpCsFixer\ToolInfo;
  17. use Symfony\Component\Console\Tester\CommandTester;
  18. /**
  19. * @internal
  20. *
  21. * @covers \PhpCsFixer\Console\Command\ListFilesCommand
  22. */
  23. final class ListFilesCommandTest extends TestCase
  24. {
  25. public function testListWithConfig(): void
  26. {
  27. $commandTester = $this->doTestExecute([
  28. '--config' => __DIR__.'/../../Fixtures/ListFilesTest/.php-cs-fixer.php',
  29. ]);
  30. $expectedPath = './tests/Fixtures/ListFilesTest/needs-fixing/needs-fixing.php';
  31. // make the test also work on Windows
  32. $expectedPath = str_replace('/', \DIRECTORY_SEPARATOR, $expectedPath);
  33. static::assertSame(0, $commandTester->getStatusCode());
  34. static::assertSame(escapeshellarg($expectedPath).PHP_EOL, $commandTester->getDisplay());
  35. }
  36. private function doTestExecute(array $arguments): CommandTester
  37. {
  38. $application = new Application();
  39. $application->add(new ListFilesCommand(new ToolInfo()));
  40. $command = $application->find('list-files');
  41. $commandTester = new CommandTester($command);
  42. $commandTester->execute($arguments);
  43. return $commandTester;
  44. }
  45. }