2018-06-28 11:37:24 +02:00
|
|
|
<?php declare(strict_types=1);
|
|
|
|
|
|
|
|
namespace Rector\Tests\FileSystem\FilesFinder;
|
|
|
|
|
|
|
|
use Iterator;
|
|
|
|
use Rector\FileSystem\FilesFinder;
|
2019-02-23 00:08:58 +01:00
|
|
|
use Rector\HttpKernel\RectorKernel;
|
2019-01-02 14:22:25 +01:00
|
|
|
use Symplify\PackageBuilder\FileSystem\SmartFileInfo;
|
2019-02-23 00:08:58 +01:00
|
|
|
use Symplify\PackageBuilder\Tests\AbstractKernelTestCase;
|
2018-06-28 11:37:24 +02:00
|
|
|
|
2019-02-23 00:08:58 +01:00
|
|
|
final class FilesFinderTest extends AbstractKernelTestCase
|
2018-06-28 11:37:24 +02:00
|
|
|
{
|
|
|
|
/**
|
|
|
|
* @var FilesFinder
|
|
|
|
*/
|
|
|
|
private $filesFinder;
|
|
|
|
|
|
|
|
protected function setUp(): void
|
|
|
|
{
|
2019-02-23 00:08:58 +01:00
|
|
|
$this->bootKernel(RectorKernel::class);
|
|
|
|
$this->filesFinder = self::$container->get(FilesFinder::class);
|
2018-06-28 11:37:24 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @dataProvider provideData()
|
|
|
|
*/
|
2018-10-04 00:50:07 +08:00
|
|
|
public function testSingleSuffix(string $suffix, int $count, string $expectedFileName): void
|
2018-06-28 11:37:24 +02:00
|
|
|
{
|
2018-10-04 00:50:07 +08:00
|
|
|
$foundFiles = $this->filesFinder->findInDirectoriesAndFiles([__DIR__ . '/FilesFinderSource'], [$suffix]);
|
2018-06-28 11:37:24 +02:00
|
|
|
$this->assertCount($count, $foundFiles);
|
|
|
|
|
2018-10-12 10:24:07 +08:00
|
|
|
/** @var SmartFileInfo $foundFile */
|
2018-06-28 11:37:24 +02:00
|
|
|
$foundFile = array_pop($foundFiles);
|
2018-10-04 00:50:07 +08:00
|
|
|
$this->assertSame($expectedFileName, $foundFile->getBasename());
|
2018-06-28 11:37:24 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
public function provideData(): Iterator
|
|
|
|
{
|
2018-10-04 00:50:07 +08:00
|
|
|
yield ['php', 1, 'SomeFile.php'];
|
|
|
|
yield ['yml', 1, 'some_config.yml'];
|
|
|
|
yield ['yaml', 1, 'other_config.yaml'];
|
|
|
|
yield ['php', 1, 'SomeFile.php'];
|
|
|
|
}
|
|
|
|
|
|
|
|
public function testMultipleSuffixes(): void
|
|
|
|
{
|
|
|
|
$foundFiles = $this->filesFinder->findInDirectoriesAndFiles([__DIR__ . '/FilesFinderSource'], ['yaml', 'yml']);
|
|
|
|
$this->assertCount(2, $foundFiles);
|
|
|
|
|
|
|
|
$foundFileNames = [];
|
|
|
|
foreach ($foundFiles as $foundFile) {
|
|
|
|
$foundFileNames[] = $foundFile->getFilename();
|
|
|
|
}
|
|
|
|
$expectedFoundFileNames = ['some_config.yml', 'other_config.yaml'];
|
|
|
|
|
|
|
|
sort($foundFileNames);
|
|
|
|
sort($expectedFoundFileNames);
|
|
|
|
$this->assertSame($expectedFoundFileNames, $foundFileNames);
|
2018-06-28 11:37:24 +02:00
|
|
|
}
|
|
|
|
}
|