2018-06-28 11:37:24 +02:00
|
|
|
<?php declare(strict_types=1);
|
|
|
|
|
|
|
|
namespace Rector\Tests\FileSystem\FilesFinder;
|
|
|
|
|
|
|
|
use Iterator;
|
|
|
|
use Rector\FileSystem\FilesFinder;
|
|
|
|
use Rector\Tests\AbstractContainerAwareTestCase;
|
2018-09-28 19:36:02 +08:00
|
|
|
use Symfony\Component\Finder\SplFileInfo;
|
2018-06-28 11:37:24 +02:00
|
|
|
|
|
|
|
final class FilesFinderTest extends AbstractContainerAwareTestCase
|
|
|
|
{
|
|
|
|
/**
|
|
|
|
* @var FilesFinder
|
|
|
|
*/
|
|
|
|
private $filesFinder;
|
|
|
|
|
|
|
|
protected function setUp(): void
|
|
|
|
{
|
|
|
|
$this->filesFinder = $this->container->get(FilesFinder::class);
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @param string[] $suffixes
|
|
|
|
* @dataProvider provideData()
|
|
|
|
*/
|
|
|
|
public function test(array $suffixes, int $count, string $fileName): void
|
|
|
|
{
|
|
|
|
$foundFiles = $this->filesFinder->findInDirectoriesAndFiles([__DIR__ . '/FilesFinderSource'], $suffixes);
|
|
|
|
$this->assertCount($count, $foundFiles);
|
|
|
|
|
2018-09-28 19:36:02 +08:00
|
|
|
/** @var SplFileInfo $foundFile */
|
2018-06-28 11:37:24 +02:00
|
|
|
$foundFile = array_pop($foundFiles);
|
|
|
|
$this->assertSame($fileName, $foundFile->getBasename());
|
|
|
|
}
|
|
|
|
|
|
|
|
public function provideData(): Iterator
|
|
|
|
{
|
|
|
|
yield [['php'], 1, 'SomeFile.php'];
|
|
|
|
yield [['yml'], 1, 'some_config.yml'];
|
2018-06-28 18:25:15 +02:00
|
|
|
yield [['yaml'], 1, 'other_config.yaml'];
|
|
|
|
yield [['php'], 1, 'SomeFile.php'];
|
|
|
|
yield [['yaml', 'yml'], 2, 'some_config.yml'];
|
2018-06-28 11:37:24 +02:00
|
|
|
}
|
|
|
|
}
|