Skip to content

Commit

Permalink
added ListFilesCommandTest
Browse files Browse the repository at this point in the history
  • Loading branch information
clxmstaab committed Apr 15, 2021
1 parent d470387 commit 7f36623
Show file tree
Hide file tree
Showing 4 changed files with 83 additions and 1 deletion.
5 changes: 4 additions & 1 deletion src/Console/Command/ListFilesCommand.php
Original file line number Diff line number Diff line change
Expand Up @@ -79,8 +79,11 @@ protected function execute(InputInterface $input, OutputInterface $output)

$finder = $resolver->getFinder();

/** @var \SplFileInfo $file */
foreach ($finder as $file) {
$output->writeln(escapeshellarg($file->getPath()));
if ($file->isFile()) {
$output->writeln(escapeshellarg($file->getPath().DIRECTORY_SEPARATOR.$file->getFilename()));
}
}

return 0;
Expand Down
53 changes: 53 additions & 0 deletions tests/Console/Command/ListFilesCommandTest.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,53 @@
<?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\ListFilesCommand;
use PhpCsFixer\Tests\TestCase;
use PhpCsFixer\ToolInfo;
use Symfony\Component\Console\Tester\CommandTester;

/**
* @internal
*
* @covers \PhpCsFixer\Console\Command\ListFilesCommand
*/
final class ListFilesCommandTest extends TestCase
{
public function testEmptyRulesValue()
{
$commandTester = $this->doTestExecute();
// TODO adjust expectation
$this->assertSame('', $commandTester->getDisplay());
}

/**
* @return CommandTester
*/
private function doTestExecute(/*array $arguments*/)
{
$application = new Application();
$application->add(new ListFilesCommand(new ToolInfo()));

$command = $application->find('list-files');
$commandTester = new CommandTester($command);

$commandTester->execute([
'--config' => __DIR__.'/test-project/.php_cs'
]
);

return $commandTester;
}
}
18 changes: 18 additions & 0 deletions tests/Console/Command/test-project/.php_cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
<?php

$finder = PhpCsFixer\Finder::create()
->in([
__DIR__
])
->exclude([
])
;

return PhpCsFixer\Config::create()
->setUsingCache(false)
->setRules([
'@Symfony' => true,
])
->setRiskyAllowed(true)
->setFinder($finder)
;
8 changes: 8 additions & 0 deletions tests/Console/Command/test-project/needs-fixing.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
<?php

function abc() {}

function def()
{

}

0 comments on commit 7f36623

Please sign in to comment.