ListFilesCommandTest.php 1.5 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455
  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(escapeshellarg($expectedPath).PHP_EOL, $commandTester->getDisplay());
  34. }
  35. private function doTestExecute(array $arguments): CommandTester
  36. {
  37. $application = new Application();
  38. $application->add(new ListFilesCommand(new ToolInfo()));
  39. $command = $application->find('list-files');
  40. $commandTester = new CommandTester($command);
  41. $commandTester->execute($arguments);
  42. return $commandTester;
  43. }
  44. }