Actualización

This commit is contained in:
Xes
2025-04-10 12:24:57 +02:00
parent 8969cc929d
commit 45420b6f0d
39760 changed files with 4303286 additions and 0 deletions

View File

@@ -0,0 +1,65 @@
<?php
/*
* This file is part of the Symfony package.
*
* (c) Fabien Potencier <fabien@symfony.com>
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*/
namespace Symfony\Component\Finder\Tests\Comparator;
use PHPUnit\Framework\TestCase;
use Symfony\Component\Finder\Comparator\Comparator;
class ComparatorTest extends TestCase
{
public function testGetSetOperator()
{
$comparator = new Comparator();
try {
$comparator->setOperator('foo');
$this->fail('->setOperator() throws an \InvalidArgumentException if the operator is not valid.');
} catch (\Exception $e) {
$this->assertInstanceOf('InvalidArgumentException', $e, '->setOperator() throws an \InvalidArgumentException if the operator is not valid.');
}
$comparator = new Comparator();
$comparator->setOperator('>');
$this->assertEquals('>', $comparator->getOperator(), '->getOperator() returns the current operator');
}
public function testGetSetTarget()
{
$comparator = new Comparator();
$comparator->setTarget(8);
$this->assertEquals(8, $comparator->getTarget(), '->getTarget() returns the target');
}
/**
* @dataProvider getTestData
*/
public function testTest($operator, $target, $match, $noMatch)
{
$c = new Comparator();
$c->setOperator($operator);
$c->setTarget($target);
foreach ($match as $m) {
$this->assertTrue($c->test($m), '->test() tests a string against the expression');
}
foreach ($noMatch as $m) {
$this->assertFalse($c->test($m), '->test() tests a string against the expression');
}
}
public function getTestData()
{
return [
['<', '1000', ['500', '999'], ['1000', '1500']],
];
}
}

View File

@@ -0,0 +1,64 @@
<?php
/*
* This file is part of the Symfony package.
*
* (c) Fabien Potencier <fabien@symfony.com>
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*/
namespace Symfony\Component\Finder\Tests\Comparator;
use PHPUnit\Framework\TestCase;
use Symfony\Component\Finder\Comparator\DateComparator;
class DateComparatorTest extends TestCase
{
public function testConstructor()
{
try {
new DateComparator('foobar');
$this->fail('__construct() throws an \InvalidArgumentException if the test expression is not valid.');
} catch (\Exception $e) {
$this->assertInstanceOf('InvalidArgumentException', $e, '__construct() throws an \InvalidArgumentException if the test expression is not valid.');
}
try {
new DateComparator('');
$this->fail('__construct() throws an \InvalidArgumentException if the test expression is not valid.');
} catch (\Exception $e) {
$this->assertInstanceOf('InvalidArgumentException', $e, '__construct() throws an \InvalidArgumentException if the test expression is not valid.');
}
}
/**
* @dataProvider getTestData
*/
public function testTest($test, $match, $noMatch)
{
$c = new DateComparator($test);
foreach ($match as $m) {
$this->assertTrue($c->test($m), '->test() tests a string against the expression');
}
foreach ($noMatch as $m) {
$this->assertFalse($c->test($m), '->test() tests a string against the expression');
}
}
public function getTestData()
{
return [
['< 2005-10-10', [strtotime('2005-10-09')], [strtotime('2005-10-15')]],
['until 2005-10-10', [strtotime('2005-10-09')], [strtotime('2005-10-15')]],
['before 2005-10-10', [strtotime('2005-10-09')], [strtotime('2005-10-15')]],
['> 2005-10-10', [strtotime('2005-10-15')], [strtotime('2005-10-09')]],
['after 2005-10-10', [strtotime('2005-10-15')], [strtotime('2005-10-09')]],
['since 2005-10-10', [strtotime('2005-10-15')], [strtotime('2005-10-09')]],
['!= 2005-10-10', [strtotime('2005-10-11')], [strtotime('2005-10-10')]],
];
}
}

View File

@@ -0,0 +1,108 @@
<?php
/*
* This file is part of the Symfony package.
*
* (c) Fabien Potencier <fabien@symfony.com>
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*/
namespace Symfony\Component\Finder\Tests\Comparator;
use PHPUnit\Framework\TestCase;
use Symfony\Component\Finder\Comparator\NumberComparator;
class NumberComparatorTest extends TestCase
{
/**
* @dataProvider getConstructorTestData
*/
public function testConstructor($successes, $failures)
{
foreach ($successes as $s) {
new NumberComparator($s);
}
foreach ($failures as $f) {
try {
new NumberComparator($f);
$this->fail('__construct() throws an \InvalidArgumentException if the test expression is not valid.');
} catch (\Exception $e) {
$this->assertInstanceOf('InvalidArgumentException', $e, '__construct() throws an \InvalidArgumentException if the test expression is not valid.');
}
}
}
/**
* @dataProvider getTestData
*/
public function testTest($test, $match, $noMatch)
{
$c = new NumberComparator($test);
foreach ($match as $m) {
$this->assertTrue($c->test($m), '->test() tests a string against the expression');
}
foreach ($noMatch as $m) {
$this->assertFalse($c->test($m), '->test() tests a string against the expression');
}
}
public function getTestData()
{
return [
['< 1000', ['500', '999'], ['1000', '1500']],
['< 1K', ['500', '999'], ['1000', '1500']],
['<1k', ['500', '999'], ['1000', '1500']],
[' < 1 K ', ['500', '999'], ['1000', '1500']],
['<= 1K', ['1000'], ['1001']],
['> 1K', ['1001'], ['1000']],
['>= 1K', ['1000'], ['999']],
['< 1KI', ['500', '1023'], ['1024', '1500']],
['<= 1KI', ['1024'], ['1025']],
['> 1KI', ['1025'], ['1024']],
['>= 1KI', ['1024'], ['1023']],
['1KI', ['1024'], ['1023', '1025']],
['==1KI', ['1024'], ['1023', '1025']],
['==1m', ['1000000'], ['999999', '1000001']],
['==1mi', [1024 * 1024], [1024 * 1024 - 1, 1024 * 1024 + 1]],
['==1g', ['1000000000'], ['999999999', '1000000001']],
['==1gi', [1024 * 1024 * 1024], [1024 * 1024 * 1024 - 1, 1024 * 1024 * 1024 + 1]],
['!= 1000', ['500', '999'], ['1000']],
];
}
public function getConstructorTestData()
{
return [
[
[
'1', '0',
'3.5', '33.55', '123.456', '123456.78',
'.1', '.123',
'.0', '0.0',
'1.', '0.', '123.',
'==1', '!=1', '<1', '>1', '<=1', '>=1',
'==1k', '==1ki', '==1m', '==1mi', '==1g', '==1gi',
'1k', '1ki', '1m', '1mi', '1g', '1gi',
],
[
false, null, '',
' ', 'foobar',
'=1', '===1',
'0 . 1', '123 .45', '234. 567',
'..', '.0.', '0.1.2',
],
],
];
}
}

View File

@@ -0,0 +1,752 @@
<?php
/*
* This file is part of the Symfony package.
*
* (c) Fabien Potencier <fabien@symfony.com>
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*/
namespace Symfony\Component\Finder\Tests;
use Symfony\Component\Finder\Finder;
class FinderTest extends Iterator\RealIteratorTestCase
{
public function testCreate()
{
$this->assertInstanceOf('Symfony\Component\Finder\Finder', Finder::create());
}
public function testDirectories()
{
$finder = $this->buildFinder();
$this->assertSame($finder, $finder->directories());
$this->assertIterator($this->toAbsolute(['foo', 'toto']), $finder->in(self::$tmpDir)->getIterator());
$finder = $this->buildFinder();
$finder->directories();
$finder->files();
$finder->directories();
$this->assertIterator($this->toAbsolute(['foo', 'toto']), $finder->in(self::$tmpDir)->getIterator());
}
public function testFiles()
{
$finder = $this->buildFinder();
$this->assertSame($finder, $finder->files());
$this->assertIterator($this->toAbsolute(['foo/bar.tmp', 'test.php', 'test.py', 'foo bar']), $finder->in(self::$tmpDir)->getIterator());
$finder = $this->buildFinder();
$finder->files();
$finder->directories();
$finder->files();
$this->assertIterator($this->toAbsolute(['foo/bar.tmp', 'test.php', 'test.py', 'foo bar']), $finder->in(self::$tmpDir)->getIterator());
}
public function testRemoveTrailingSlash()
{
$finder = $this->buildFinder();
$expected = $this->toAbsolute(['foo/bar.tmp', 'test.php', 'test.py', 'foo bar']);
$in = self::$tmpDir.'//';
$this->assertIterator($expected, $finder->in($in)->files()->getIterator());
}
public function testSymlinksNotResolved()
{
if ('\\' === \DIRECTORY_SEPARATOR) {
$this->markTestSkipped('symlinks are not supported on Windows');
}
$finder = $this->buildFinder();
symlink($this->toAbsolute('foo'), $this->toAbsolute('baz'));
$expected = $this->toAbsolute(['baz/bar.tmp']);
$in = self::$tmpDir.'/baz/';
try {
$this->assertIterator($expected, $finder->in($in)->files()->getIterator());
unlink($this->toAbsolute('baz'));
} catch (\Exception $e) {
unlink($this->toAbsolute('baz'));
throw $e;
}
}
public function testBackPathNotNormalized()
{
$finder = $this->buildFinder();
$expected = $this->toAbsolute(['foo/../foo/bar.tmp']);
$in = self::$tmpDir.'/foo/../foo/';
$this->assertIterator($expected, $finder->in($in)->files()->getIterator());
}
public function testDepth()
{
$finder = $this->buildFinder();
$this->assertSame($finder, $finder->depth('< 1'));
$this->assertIterator($this->toAbsolute(['foo', 'test.php', 'test.py', 'toto', 'foo bar']), $finder->in(self::$tmpDir)->getIterator());
$finder = $this->buildFinder();
$this->assertSame($finder, $finder->depth('<= 0'));
$this->assertIterator($this->toAbsolute(['foo', 'test.php', 'test.py', 'toto', 'foo bar']), $finder->in(self::$tmpDir)->getIterator());
$finder = $this->buildFinder();
$this->assertSame($finder, $finder->depth('>= 1'));
$this->assertIterator($this->toAbsolute(['foo/bar.tmp']), $finder->in(self::$tmpDir)->getIterator());
$finder = $this->buildFinder();
$finder->depth('< 1')->depth('>= 1');
$this->assertIterator([], $finder->in(self::$tmpDir)->getIterator());
}
public function testName()
{
$finder = $this->buildFinder();
$this->assertSame($finder, $finder->name('*.php'));
$this->assertIterator($this->toAbsolute(['test.php']), $finder->in(self::$tmpDir)->getIterator());
$finder = $this->buildFinder();
$finder->name('test.ph*');
$finder->name('test.py');
$this->assertIterator($this->toAbsolute(['test.php', 'test.py']), $finder->in(self::$tmpDir)->getIterator());
$finder = $this->buildFinder();
$finder->name('~^test~i');
$this->assertIterator($this->toAbsolute(['test.php', 'test.py']), $finder->in(self::$tmpDir)->getIterator());
$finder = $this->buildFinder();
$finder->name('~\\.php$~i');
$this->assertIterator($this->toAbsolute(['test.php']), $finder->in(self::$tmpDir)->getIterator());
$finder = $this->buildFinder();
$finder->name('test.p{hp,y}');
$this->assertIterator($this->toAbsolute(['test.php', 'test.py']), $finder->in(self::$tmpDir)->getIterator());
}
public function testNotName()
{
$finder = $this->buildFinder();
$this->assertSame($finder, $finder->notName('*.php'));
$this->assertIterator($this->toAbsolute(['foo', 'foo/bar.tmp', 'test.py', 'toto', 'foo bar']), $finder->in(self::$tmpDir)->getIterator());
$finder = $this->buildFinder();
$finder->notName('*.php');
$finder->notName('*.py');
$this->assertIterator($this->toAbsolute(['foo', 'foo/bar.tmp', 'toto', 'foo bar']), $finder->in(self::$tmpDir)->getIterator());
$finder = $this->buildFinder();
$finder->name('test.ph*');
$finder->name('test.py');
$finder->notName('*.php');
$finder->notName('*.py');
$this->assertIterator([], $finder->in(self::$tmpDir)->getIterator());
$finder = $this->buildFinder();
$finder->name('test.ph*');
$finder->name('test.py');
$finder->notName('*.p{hp,y}');
$this->assertIterator([], $finder->in(self::$tmpDir)->getIterator());
}
/**
* @dataProvider getRegexNameTestData
*/
public function testRegexName($regex)
{
$finder = $this->buildFinder();
$finder->name($regex);
$this->assertIterator($this->toAbsolute(['test.py', 'test.php']), $finder->in(self::$tmpDir)->getIterator());
}
public function testSize()
{
$finder = $this->buildFinder();
$this->assertSame($finder, $finder->files()->size('< 1K')->size('> 500'));
$this->assertIterator($this->toAbsolute(['test.php']), $finder->in(self::$tmpDir)->getIterator());
}
public function testDate()
{
$finder = $this->buildFinder();
$this->assertSame($finder, $finder->files()->date('until last month'));
$this->assertIterator($this->toAbsolute(['foo/bar.tmp', 'test.php']), $finder->in(self::$tmpDir)->getIterator());
}
public function testExclude()
{
$finder = $this->buildFinder();
$this->assertSame($finder, $finder->exclude('foo'));
$this->assertIterator($this->toAbsolute(['test.php', 'test.py', 'toto', 'foo bar']), $finder->in(self::$tmpDir)->getIterator());
}
public function testIgnoreVCS()
{
$finder = $this->buildFinder();
$this->assertSame($finder, $finder->ignoreVCS(false)->ignoreDotFiles(false));
$this->assertIterator($this->toAbsolute(['.git', 'foo', 'foo/bar.tmp', 'test.php', 'test.py', 'toto', 'toto/.git', '.bar', '.foo', '.foo/.bar', '.foo/bar', 'foo bar']), $finder->in(self::$tmpDir)->getIterator());
$finder = $this->buildFinder();
$finder->ignoreVCS(false)->ignoreVCS(false)->ignoreDotFiles(false);
$this->assertIterator($this->toAbsolute(['.git', 'foo', 'foo/bar.tmp', 'test.php', 'test.py', 'toto', 'toto/.git', '.bar', '.foo', '.foo/.bar', '.foo/bar', 'foo bar']), $finder->in(self::$tmpDir)->getIterator());
$finder = $this->buildFinder();
$this->assertSame($finder, $finder->ignoreVCS(true)->ignoreDotFiles(false));
$this->assertIterator($this->toAbsolute(['foo', 'foo/bar.tmp', 'test.php', 'test.py', 'toto', '.bar', '.foo', '.foo/.bar', '.foo/bar', 'foo bar']), $finder->in(self::$tmpDir)->getIterator());
}
public function testIgnoreVCSCanBeDisabledAfterFirstIteration()
{
$finder = $this->buildFinder();
$finder->in(self::$tmpDir);
$finder->ignoreDotFiles(false);
$this->assertIterator($this->toAbsolute(['foo', 'foo/bar.tmp', 'test.php', 'test.py', 'toto', '.bar', '.foo', '.foo/.bar', '.foo/bar', 'foo bar']), $finder->getIterator());
$finder->ignoreVCS(false);
$this->assertIterator($this->toAbsolute(['.git', 'foo', 'foo/bar.tmp', 'test.php', 'test.py', 'toto', 'toto/.git', '.bar', '.foo', '.foo/.bar', '.foo/bar', 'foo bar']), $finder->getIterator());
}
public function testIgnoreDotFiles()
{
$finder = $this->buildFinder();
$this->assertSame($finder, $finder->ignoreDotFiles(false)->ignoreVCS(false));
$this->assertIterator($this->toAbsolute(['.git', '.bar', '.foo', '.foo/.bar', '.foo/bar', 'foo', 'foo/bar.tmp', 'test.php', 'test.py', 'toto', 'toto/.git', 'foo bar']), $finder->in(self::$tmpDir)->getIterator());
$finder = $this->buildFinder();
$finder->ignoreDotFiles(false)->ignoreDotFiles(false)->ignoreVCS(false);
$this->assertIterator($this->toAbsolute(['.git', '.bar', '.foo', '.foo/.bar', '.foo/bar', 'foo', 'foo/bar.tmp', 'test.php', 'test.py', 'toto', 'toto/.git', 'foo bar']), $finder->in(self::$tmpDir)->getIterator());
$finder = $this->buildFinder();
$this->assertSame($finder, $finder->ignoreDotFiles(true)->ignoreVCS(false));
$this->assertIterator($this->toAbsolute(['foo', 'foo/bar.tmp', 'test.php', 'test.py', 'toto', 'foo bar']), $finder->in(self::$tmpDir)->getIterator());
}
public function testIgnoreDotFilesCanBeDisabledAfterFirstIteration()
{
$finder = $this->buildFinder();
$finder->in(self::$tmpDir);
$this->assertIterator($this->toAbsolute(['foo', 'foo/bar.tmp', 'test.php', 'test.py', 'toto', 'foo bar']), $finder->getIterator());
$finder->ignoreDotFiles(false);
$this->assertIterator($this->toAbsolute(['foo', 'foo/bar.tmp', 'test.php', 'test.py', 'toto', '.bar', '.foo', '.foo/.bar', '.foo/bar', 'foo bar']), $finder->getIterator());
}
public function testSortByName()
{
$finder = $this->buildFinder();
$this->assertSame($finder, $finder->sortByName());
$this->assertIterator($this->toAbsolute(['foo', 'foo bar', 'foo/bar.tmp', 'test.php', 'test.py', 'toto']), $finder->in(self::$tmpDir)->getIterator());
}
public function testSortByType()
{
$finder = $this->buildFinder();
$this->assertSame($finder, $finder->sortByType());
$this->assertIterator($this->toAbsolute(['foo', 'foo bar', 'toto', 'foo/bar.tmp', 'test.php', 'test.py']), $finder->in(self::$tmpDir)->getIterator());
}
public function testSortByAccessedTime()
{
$finder = $this->buildFinder();
$this->assertSame($finder, $finder->sortByAccessedTime());
$this->assertIterator($this->toAbsolute(['foo/bar.tmp', 'test.php', 'toto', 'test.py', 'foo', 'foo bar']), $finder->in(self::$tmpDir)->getIterator());
}
public function testSortByChangedTime()
{
$finder = $this->buildFinder();
$this->assertSame($finder, $finder->sortByChangedTime());
$this->assertIterator($this->toAbsolute(['toto', 'test.py', 'test.php', 'foo/bar.tmp', 'foo', 'foo bar']), $finder->in(self::$tmpDir)->getIterator());
}
public function testSortByModifiedTime()
{
$finder = $this->buildFinder();
$this->assertSame($finder, $finder->sortByModifiedTime());
$this->assertIterator($this->toAbsolute(['foo/bar.tmp', 'test.php', 'toto', 'test.py', 'foo', 'foo bar']), $finder->in(self::$tmpDir)->getIterator());
}
public function testSort()
{
$finder = $this->buildFinder();
$this->assertSame($finder, $finder->sort(function (\SplFileInfo $a, \SplFileInfo $b) { return strcmp($a->getRealPath(), $b->getRealPath()); }));
$this->assertIterator($this->toAbsolute(['foo', 'foo bar', 'foo/bar.tmp', 'test.php', 'test.py', 'toto']), $finder->in(self::$tmpDir)->getIterator());
}
public function testFilter()
{
$finder = $this->buildFinder();
$this->assertSame($finder, $finder->filter(function (\SplFileInfo $f) { return false !== strpos($f, 'test'); }));
$this->assertIterator($this->toAbsolute(['test.php', 'test.py']), $finder->in(self::$tmpDir)->getIterator());
}
public function testFollowLinks()
{
if ('\\' == \DIRECTORY_SEPARATOR) {
$this->markTestSkipped('symlinks are not supported on Windows');
}
$finder = $this->buildFinder();
$this->assertSame($finder, $finder->followLinks());
$this->assertIterator($this->toAbsolute(['foo', 'foo/bar.tmp', 'test.php', 'test.py', 'toto', 'foo bar']), $finder->in(self::$tmpDir)->getIterator());
}
public function testIn()
{
$finder = $this->buildFinder();
$iterator = $finder->files()->name('*.php')->depth('< 1')->in([self::$tmpDir, __DIR__])->getIterator();
$expected = [
self::$tmpDir.\DIRECTORY_SEPARATOR.'test.php',
__DIR__.\DIRECTORY_SEPARATOR.'FinderTest.php',
__DIR__.\DIRECTORY_SEPARATOR.'GlobTest.php',
];
$this->assertIterator($expected, $iterator);
}
public function testInWithNonExistentDirectory()
{
$this->expectException('InvalidArgumentException');
$finder = new Finder();
$finder->in('foobar');
}
public function testInWithGlob()
{
$finder = $this->buildFinder();
$finder->in([__DIR__.'/Fixtures/*/B/C/', __DIR__.'/Fixtures/*/*/B/C/'])->getIterator();
$this->assertIterator($this->toAbsoluteFixtures(['A/B/C/abc.dat', 'copy/A/B/C/abc.dat.copy']), $finder);
}
public function testInWithNonDirectoryGlob()
{
$this->expectException('InvalidArgumentException');
$finder = new Finder();
$finder->in(__DIR__.'/Fixtures/A/a*');
}
public function testInWithGlobBrace()
{
if (!\defined('GLOB_BRACE')) {
$this->markTestSkipped('Glob brace is not supported on this system.');
}
$finder = $this->buildFinder();
$finder->in([__DIR__.'/Fixtures/{A,copy/A}/B/C'])->getIterator();
$this->assertIterator($this->toAbsoluteFixtures(['A/B/C/abc.dat', 'copy/A/B/C/abc.dat.copy']), $finder);
}
public function testGetIteratorWithoutIn()
{
$this->expectException('LogicException');
$finder = Finder::create();
$finder->getIterator();
}
public function testGetIterator()
{
$finder = $this->buildFinder();
$dirs = [];
foreach ($finder->directories()->in(self::$tmpDir) as $dir) {
$dirs[] = (string) $dir;
}
$expected = $this->toAbsolute(['foo', 'toto']);
sort($dirs);
sort($expected);
$this->assertEquals($expected, $dirs, 'implements the \IteratorAggregate interface');
$finder = $this->buildFinder();
$this->assertEquals(2, iterator_count($finder->directories()->in(self::$tmpDir)), 'implements the \IteratorAggregate interface');
$finder = $this->buildFinder();
$a = iterator_to_array($finder->directories()->in(self::$tmpDir));
$a = array_values(array_map('strval', $a));
sort($a);
$this->assertEquals($expected, $a, 'implements the \IteratorAggregate interface');
}
public function testRelativePath()
{
$finder = $this->buildFinder()->in(self::$tmpDir);
$paths = [];
foreach ($finder as $file) {
$paths[] = $file->getRelativePath();
}
$ref = ['', '', '', '', 'foo', ''];
sort($ref);
sort($paths);
$this->assertEquals($ref, $paths);
}
public function testRelativePathname()
{
$finder = $this->buildFinder()->in(self::$tmpDir)->sortByName();
$paths = [];
foreach ($finder as $file) {
$paths[] = $file->getRelativePathname();
}
$ref = ['test.php', 'toto', 'test.py', 'foo', 'foo'.\DIRECTORY_SEPARATOR.'bar.tmp', 'foo bar'];
sort($paths);
sort($ref);
$this->assertEquals($ref, $paths);
}
public function testAppendWithAFinder()
{
$finder = $this->buildFinder();
$finder->files()->in(self::$tmpDir.\DIRECTORY_SEPARATOR.'foo');
$finder1 = $this->buildFinder();
$finder1->directories()->in(self::$tmpDir);
$finder = $finder->append($finder1);
$this->assertIterator($this->toAbsolute(['foo', 'foo/bar.tmp', 'toto']), $finder->getIterator());
}
public function testAppendWithAnArray()
{
$finder = $this->buildFinder();
$finder->files()->in(self::$tmpDir.\DIRECTORY_SEPARATOR.'foo');
$finder->append($this->toAbsolute(['foo', 'toto']));
$this->assertIterator($this->toAbsolute(['foo', 'foo/bar.tmp', 'toto']), $finder->getIterator());
}
public function testAppendReturnsAFinder()
{
$this->assertInstanceOf('Symfony\\Component\\Finder\\Finder', Finder::create()->append([]));
}
public function testAppendDoesNotRequireIn()
{
$finder = $this->buildFinder();
$finder->in(self::$tmpDir.\DIRECTORY_SEPARATOR.'foo');
$finder1 = Finder::create()->append($finder);
$this->assertIterator(iterator_to_array($finder->getIterator()), $finder1->getIterator());
}
public function testCountDirectories()
{
$directory = Finder::create()->directories()->in(self::$tmpDir);
$i = 0;
foreach ($directory as $dir) {
++$i;
}
$this->assertCount($i, $directory);
}
public function testCountFiles()
{
$files = Finder::create()->files()->in(__DIR__.\DIRECTORY_SEPARATOR.'Fixtures');
$i = 0;
foreach ($files as $file) {
++$i;
}
$this->assertCount($i, $files);
}
public function testCountWithoutIn()
{
$this->expectException('LogicException');
$finder = Finder::create()->files();
\count($finder);
}
public function testHasResults()
{
$finder = $this->buildFinder();
$finder->in(__DIR__);
$this->assertTrue($finder->hasResults());
}
public function testNoResults()
{
$finder = $this->buildFinder();
$finder->in(__DIR__)->name('DoesNotExist');
$this->assertFalse($finder->hasResults());
}
/**
* @dataProvider getContainsTestData
*/
public function testContains($matchPatterns, $noMatchPatterns, $expected)
{
$finder = $this->buildFinder();
$finder->in(__DIR__.\DIRECTORY_SEPARATOR.'Fixtures')
->name('*.txt')->sortByName()
->contains($matchPatterns)
->notContains($noMatchPatterns);
$this->assertIterator($this->toAbsoluteFixtures($expected), $finder);
}
public function testContainsOnDirectory()
{
$finder = $this->buildFinder();
$finder->in(__DIR__)
->directories()
->name('Fixtures')
->contains('abc');
$this->assertIterator([], $finder);
}
public function testNotContainsOnDirectory()
{
$finder = $this->buildFinder();
$finder->in(__DIR__)
->directories()
->name('Fixtures')
->notContains('abc');
$this->assertIterator([], $finder);
}
/**
* Searching in multiple locations involves AppendIterator which does an unnecessary rewind which leaves FilterIterator
* with inner FilesystemIterator in an invalid state.
*
* @see https://bugs.php.net/68557
*/
public function testMultipleLocations()
{
$locations = [
self::$tmpDir.'/',
self::$tmpDir.'/toto/',
];
// it is expected that there are test.py test.php in the tmpDir
$finder = new Finder();
$finder->in($locations)
// the default flag IGNORE_DOT_FILES fixes the problem indirectly
// so we set it to false for better isolation
->ignoreDotFiles(false)
->depth('< 1')->name('test.php');
$this->assertCount(1, $finder);
}
/**
* Searching in multiple locations with sub directories involves
* AppendIterator which does an unnecessary rewind which leaves
* FilterIterator with inner FilesystemIterator in an invalid state.
*
* @see https://bugs.php.net/68557
*/
public function testMultipleLocationsWithSubDirectories()
{
$locations = [
__DIR__.'/Fixtures/one',
self::$tmpDir.\DIRECTORY_SEPARATOR.'toto',
];
$finder = $this->buildFinder();
$finder->in($locations)->depth('< 10')->name('*.neon');
$expected = [
__DIR__.'/Fixtures/one'.\DIRECTORY_SEPARATOR.'b'.\DIRECTORY_SEPARATOR.'c.neon',
__DIR__.'/Fixtures/one'.\DIRECTORY_SEPARATOR.'b'.\DIRECTORY_SEPARATOR.'d.neon',
];
$this->assertIterator($expected, $finder);
$this->assertIteratorInForeach($expected, $finder);
}
/**
* Iterator keys must be the file pathname.
*/
public function testIteratorKeys()
{
$finder = $this->buildFinder()->in(self::$tmpDir);
foreach ($finder as $key => $file) {
$this->assertEquals($file->getPathname(), $key);
}
}
public function testRegexSpecialCharsLocationWithPathRestrictionContainingStartFlag()
{
$finder = $this->buildFinder();
$finder->in(__DIR__.\DIRECTORY_SEPARATOR.'Fixtures'.\DIRECTORY_SEPARATOR.'r+e.gex[c]a(r)s')
->path('/^dir/');
$expected = ['r+e.gex[c]a(r)s'.\DIRECTORY_SEPARATOR.'dir', 'r+e.gex[c]a(r)s'.\DIRECTORY_SEPARATOR.'dir'.\DIRECTORY_SEPARATOR.'bar.dat'];
$this->assertIterator($this->toAbsoluteFixtures($expected), $finder);
}
public function getContainsTestData()
{
return [
['', '', []],
['foo', 'bar', []],
['', 'foobar', ['dolor.txt', 'ipsum.txt', 'lorem.txt']],
['lorem ipsum dolor sit amet', 'foobar', ['lorem.txt']],
['sit', 'bar', ['dolor.txt', 'ipsum.txt', 'lorem.txt']],
['dolor sit amet', '@^L@m', ['dolor.txt', 'ipsum.txt']],
['/^lorem ipsum dolor sit amet$/m', 'foobar', ['lorem.txt']],
['lorem', 'foobar', ['lorem.txt']],
['', 'lorem', ['dolor.txt', 'ipsum.txt']],
['ipsum dolor sit amet', '/^IPSUM/m', ['lorem.txt']],
];
}
public function getRegexNameTestData()
{
return [
['~.+\\.p.+~i'],
['~t.*s~i'],
];
}
/**
* @dataProvider getTestPathData
*/
public function testPath($matchPatterns, $noMatchPatterns, array $expected)
{
$finder = $this->buildFinder();
$finder->in(__DIR__.\DIRECTORY_SEPARATOR.'Fixtures')
->path($matchPatterns)
->notPath($noMatchPatterns);
$this->assertIterator($this->toAbsoluteFixtures($expected), $finder);
}
public function getTestPathData()
{
return [
['', '', []],
['/^A\/B\/C/', '/C$/',
['A'.\DIRECTORY_SEPARATOR.'B'.\DIRECTORY_SEPARATOR.'C'.\DIRECTORY_SEPARATOR.'abc.dat'],
],
['/^A\/B/', 'foobar',
[
'A'.\DIRECTORY_SEPARATOR.'B',
'A'.\DIRECTORY_SEPARATOR.'B'.\DIRECTORY_SEPARATOR.'C',
'A'.\DIRECTORY_SEPARATOR.'B'.\DIRECTORY_SEPARATOR.'ab.dat',
'A'.\DIRECTORY_SEPARATOR.'B'.\DIRECTORY_SEPARATOR.'C'.\DIRECTORY_SEPARATOR.'abc.dat',
],
],
['A/B/C', 'foobar',
[
'A'.\DIRECTORY_SEPARATOR.'B'.\DIRECTORY_SEPARATOR.'C',
'A'.\DIRECTORY_SEPARATOR.'B'.\DIRECTORY_SEPARATOR.'C'.\DIRECTORY_SEPARATOR.'abc.dat',
'copy'.\DIRECTORY_SEPARATOR.'A'.\DIRECTORY_SEPARATOR.'B'.\DIRECTORY_SEPARATOR.'C',
'copy'.\DIRECTORY_SEPARATOR.'A'.\DIRECTORY_SEPARATOR.'B'.\DIRECTORY_SEPARATOR.'C'.\DIRECTORY_SEPARATOR.'abc.dat.copy',
],
],
['A/B', 'foobar',
[
//dirs
'A'.\DIRECTORY_SEPARATOR.'B',
'A'.\DIRECTORY_SEPARATOR.'B'.\DIRECTORY_SEPARATOR.'C',
'copy'.\DIRECTORY_SEPARATOR.'A'.\DIRECTORY_SEPARATOR.'B',
'copy'.\DIRECTORY_SEPARATOR.'A'.\DIRECTORY_SEPARATOR.'B'.\DIRECTORY_SEPARATOR.'C',
//files
'A'.\DIRECTORY_SEPARATOR.'B'.\DIRECTORY_SEPARATOR.'ab.dat',
'A'.\DIRECTORY_SEPARATOR.'B'.\DIRECTORY_SEPARATOR.'C'.\DIRECTORY_SEPARATOR.'abc.dat',
'copy'.\DIRECTORY_SEPARATOR.'A'.\DIRECTORY_SEPARATOR.'B'.\DIRECTORY_SEPARATOR.'ab.dat.copy',
'copy'.\DIRECTORY_SEPARATOR.'A'.\DIRECTORY_SEPARATOR.'B'.\DIRECTORY_SEPARATOR.'C'.\DIRECTORY_SEPARATOR.'abc.dat.copy',
],
],
['/^with space\//', 'foobar',
[
'with space'.\DIRECTORY_SEPARATOR.'foo.txt',
],
],
];
}
public function testAccessDeniedException()
{
if ('\\' === \DIRECTORY_SEPARATOR) {
$this->markTestSkipped('chmod is not supported on Windows');
}
$finder = $this->buildFinder();
$finder->files()->in(self::$tmpDir);
// make 'foo' directory non-readable
$testDir = self::$tmpDir.\DIRECTORY_SEPARATOR.'foo';
chmod($testDir, 0333);
if (false === $couldRead = is_readable($testDir)) {
try {
$this->assertIterator($this->toAbsolute(['foo bar', 'test.php', 'test.py']), $finder->getIterator());
$this->fail('Finder should throw an exception when opening a non-readable directory.');
} catch (\Exception $e) {
$expectedExceptionClass = 'Symfony\\Component\\Finder\\Exception\\AccessDeniedException';
if ($e instanceof \PHPUnit\Framework\ExpectationFailedException) {
$this->fail(sprintf("Expected exception:\n%s\nGot:\n%s\nWith comparison failure:\n%s", $expectedExceptionClass, 'PHPUnit\Framework\ExpectationFailedException', $e->getComparisonFailure()->getExpectedAsString()));
}
$this->assertInstanceOf($expectedExceptionClass, $e);
}
}
// restore original permissions
chmod($testDir, 0777);
clearstatcache(true, $testDir);
if ($couldRead) {
$this->markTestSkipped('could read test files while test requires unreadable');
}
}
public function testIgnoredAccessDeniedException()
{
if ('\\' === \DIRECTORY_SEPARATOR) {
$this->markTestSkipped('chmod is not supported on Windows');
}
$finder = $this->buildFinder();
$finder->files()->ignoreUnreadableDirs()->in(self::$tmpDir);
// make 'foo' directory non-readable
$testDir = self::$tmpDir.\DIRECTORY_SEPARATOR.'foo';
chmod($testDir, 0333);
if (false === ($couldRead = is_readable($testDir))) {
$this->assertIterator($this->toAbsolute(['foo bar', 'test.php', 'test.py']), $finder->getIterator());
}
// restore original permissions
chmod($testDir, 0777);
clearstatcache(true, $testDir);
if ($couldRead) {
$this->markTestSkipped('could read test files while test requires unreadable');
}
}
protected function buildFinder()
{
return Finder::create();
}
}

View File

View File

View File

View File

View File

View File

View File

View File

@@ -0,0 +1,2 @@
dolor sit amet
DOLOR SIT AMET

View File

@@ -0,0 +1,2 @@
ipsum dolor sit amet
IPSUM DOLOR SIT AMET

View File

@@ -0,0 +1,2 @@
lorem ipsum dolor sit amet
LOREM IPSUM DOLOR SIT AMET

View File

@@ -0,0 +1 @@
.dot

View File

View File

View File

View File

@@ -0,0 +1,95 @@
<?php
/*
* This file is part of the Symfony package.
*
* (c) Fabien Potencier <fabien@symfony.com>
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*/
namespace Symfony\Component\Finder\Tests;
use PHPUnit\Framework\TestCase;
use Symfony\Component\Finder\Finder;
use Symfony\Component\Finder\Glob;
class GlobTest extends TestCase
{
public function testGlobToRegexDelimiters()
{
$this->assertEquals('#^(?=[^\.])\#$#', Glob::toRegex('#'));
$this->assertEquals('#^\.[^/]*$#', Glob::toRegex('.*'));
$this->assertEquals('^\.[^/]*$', Glob::toRegex('.*', true, true, ''));
$this->assertEquals('/^\.[^/]*$/', Glob::toRegex('.*', true, true, '/'));
}
public function testGlobToRegexDoubleStarStrictDots()
{
$finder = new Finder();
$finder->ignoreDotFiles(false);
$regex = Glob::toRegex('/**/*.neon');
foreach ($finder->in(__DIR__) as $k => $v) {
$k = str_replace(\DIRECTORY_SEPARATOR, '/', $k);
if (preg_match($regex, substr($k, \strlen(__DIR__)))) {
$match[] = substr($k, 10 + \strlen(__DIR__));
}
}
sort($match);
$this->assertSame(['one/b/c.neon', 'one/b/d.neon'], $match);
}
public function testGlobToRegexDoubleStarNonStrictDots()
{
$finder = new Finder();
$finder->ignoreDotFiles(false);
$regex = Glob::toRegex('/**/*.neon', false);
foreach ($finder->in(__DIR__) as $k => $v) {
$k = str_replace(\DIRECTORY_SEPARATOR, '/', $k);
if (preg_match($regex, substr($k, \strlen(__DIR__)))) {
$match[] = substr($k, 10 + \strlen(__DIR__));
}
}
sort($match);
$this->assertSame(['.dot/b/c.neon', '.dot/b/d.neon', 'one/b/c.neon', 'one/b/d.neon'], $match);
}
public function testGlobToRegexDoubleStarWithoutLeadingSlash()
{
$finder = new Finder();
$finder->ignoreDotFiles(false);
$regex = Glob::toRegex('/Fixtures/one/**');
foreach ($finder->in(__DIR__) as $k => $v) {
$k = str_replace(\DIRECTORY_SEPARATOR, '/', $k);
if (preg_match($regex, substr($k, \strlen(__DIR__)))) {
$match[] = substr($k, 10 + \strlen(__DIR__));
}
}
sort($match);
$this->assertSame(['one/a', 'one/b', 'one/b/c.neon', 'one/b/d.neon'], $match);
}
public function testGlobToRegexDoubleStarWithoutLeadingSlashNotStrictLeadingDot()
{
$finder = new Finder();
$finder->ignoreDotFiles(false);
$regex = Glob::toRegex('/Fixtures/one/**', false);
foreach ($finder->in(__DIR__) as $k => $v) {
$k = str_replace(\DIRECTORY_SEPARATOR, '/', $k);
if (preg_match($regex, substr($k, \strlen(__DIR__)))) {
$match[] = substr($k, 10 + \strlen(__DIR__));
}
}
sort($match);
$this->assertSame(['one/.dot', 'one/a', 'one/b', 'one/b/c.neon', 'one/b/d.neon'], $match);
}
}

View File

@@ -0,0 +1,44 @@
<?php
/*
* This file is part of the Symfony package.
*
* (c) Fabien Potencier <fabien@symfony.com>
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*/
namespace Symfony\Component\Finder\Tests\Iterator;
use Symfony\Component\Finder\Iterator\CustomFilterIterator;
class CustomFilterIteratorTest extends IteratorTestCase
{
public function testWithInvalidFilter()
{
$this->expectException('InvalidArgumentException');
new CustomFilterIterator(new Iterator(), ['foo']);
}
/**
* @dataProvider getAcceptData
*/
public function testAccept($filters, $expected)
{
$inner = new Iterator(['test.php', 'test.py', 'foo.php']);
$iterator = new CustomFilterIterator($inner, $filters);
$this->assertIterator($expected, $iterator);
}
public function getAcceptData()
{
return [
[[function (\SplFileInfo $fileinfo) { return false; }], []],
[[function (\SplFileInfo $fileinfo) { return 0 === strpos($fileinfo, 'test'); }], ['test.php', 'test.py']],
[['is_dir'], []],
];
}
}

View File

@@ -0,0 +1,74 @@
<?php
/*
* This file is part of the Symfony package.
*
* (c) Fabien Potencier <fabien@symfony.com>
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*/
namespace Symfony\Component\Finder\Tests\Iterator;
use Symfony\Component\Finder\Comparator\DateComparator;
use Symfony\Component\Finder\Iterator\DateRangeFilterIterator;
class DateRangeFilterIteratorTest extends RealIteratorTestCase
{
/**
* @dataProvider getAcceptData
*/
public function testAccept($size, $expected)
{
$files = self::$files;
$files[] = self::toAbsolute('doesnotexist');
$inner = new Iterator($files);
$iterator = new DateRangeFilterIterator($inner, $size);
$this->assertIterator($expected, $iterator);
}
public function getAcceptData()
{
$since20YearsAgo = [
'.git',
'test.py',
'foo',
'foo/bar.tmp',
'test.php',
'toto',
'toto/.git',
'.bar',
'.foo',
'.foo/.bar',
'foo bar',
'.foo/bar',
];
$since2MonthsAgo = [
'.git',
'test.py',
'foo',
'toto',
'toto/.git',
'.bar',
'.foo',
'.foo/.bar',
'foo bar',
'.foo/bar',
];
$untilLastMonth = [
'foo/bar.tmp',
'test.php',
];
return [
[[new DateComparator('since 20 years ago')], $this->toAbsolute($since20YearsAgo)],
[[new DateComparator('since 2 months ago')], $this->toAbsolute($since2MonthsAgo)],
[[new DateComparator('until last month')], $this->toAbsolute($untilLastMonth)],
];
}
}

View File

@@ -0,0 +1,83 @@
<?php
/*
* This file is part of the Symfony package.
*
* (c) Fabien Potencier <fabien@symfony.com>
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*/
namespace Symfony\Component\Finder\Tests\Iterator;
use Symfony\Component\Finder\Iterator\DepthRangeFilterIterator;
class DepthRangeFilterIteratorTest extends RealIteratorTestCase
{
/**
* @dataProvider getAcceptData
*/
public function testAccept($minDepth, $maxDepth, $expected)
{
$inner = new \RecursiveIteratorIterator(new \RecursiveDirectoryIterator($this->toAbsolute(), \FilesystemIterator::SKIP_DOTS), \RecursiveIteratorIterator::SELF_FIRST);
$iterator = new DepthRangeFilterIterator($inner, $minDepth, $maxDepth);
$actual = array_keys(iterator_to_array($iterator));
sort($expected);
sort($actual);
$this->assertEquals($expected, $actual);
}
public function getAcceptData()
{
$lessThan1 = [
'.git',
'test.py',
'foo',
'test.php',
'toto',
'.foo',
'.bar',
'foo bar',
];
$lessThanOrEqualTo1 = [
'.git',
'test.py',
'foo',
'foo/bar.tmp',
'test.php',
'toto',
'toto/.git',
'.foo',
'.foo/.bar',
'.bar',
'foo bar',
'.foo/bar',
];
$graterThanOrEqualTo1 = [
'toto/.git',
'foo/bar.tmp',
'.foo/.bar',
'.foo/bar',
];
$equalTo1 = [
'toto/.git',
'foo/bar.tmp',
'.foo/.bar',
'.foo/bar',
];
return [
[0, 0, $this->toAbsolute($lessThan1)],
[0, 1, $this->toAbsolute($lessThanOrEqualTo1)],
[2, \PHP_INT_MAX, []],
[1, \PHP_INT_MAX, $this->toAbsolute($graterThanOrEqualTo1)],
[1, 1, $this->toAbsolute($equalTo1)],
];
}
}

View File

@@ -0,0 +1,80 @@
<?php
/*
* This file is part of the Symfony package.
*
* (c) Fabien Potencier <fabien@symfony.com>
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*/
namespace Symfony\Component\Finder\Tests\Iterator;
use Symfony\Component\Finder\Iterator\ExcludeDirectoryFilterIterator;
use Symfony\Component\Finder\Iterator\RecursiveDirectoryIterator;
class ExcludeDirectoryFilterIteratorTest extends RealIteratorTestCase
{
/**
* @dataProvider getAcceptData
*/
public function testAccept($directories, $expected)
{
$inner = new \RecursiveIteratorIterator(new RecursiveDirectoryIterator($this->toAbsolute(), \FilesystemIterator::SKIP_DOTS), \RecursiveIteratorIterator::SELF_FIRST);
$iterator = new ExcludeDirectoryFilterIterator($inner, $directories);
$this->assertIterator($expected, $iterator);
}
public function getAcceptData()
{
$foo = [
'.bar',
'.foo',
'.foo/.bar',
'.foo/bar',
'.git',
'test.py',
'test.php',
'toto',
'toto/.git',
'foo bar',
];
$fo = [
'.bar',
'.foo',
'.foo/.bar',
'.foo/bar',
'.git',
'test.py',
'foo',
'foo/bar.tmp',
'test.php',
'toto',
'toto/.git',
'foo bar',
];
$toto = [
'.bar',
'.foo',
'.foo/.bar',
'.foo/bar',
'.git',
'test.py',
'foo',
'foo/bar.tmp',
'test.php',
'foo bar',
];
return [
[['foo'], $this->toAbsolute($foo)],
[['fo'], $this->toAbsolute($fo)],
[['toto/'], $this->toAbsolute($toto)],
];
}
}

View File

@@ -0,0 +1,73 @@
<?php
/*
* This file is part of the Symfony package.
*
* (c) Fabien Potencier <fabien@symfony.com>
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*/
namespace Symfony\Component\Finder\Tests\Iterator;
use Symfony\Component\Finder\Iterator\FileTypeFilterIterator;
class FileTypeFilterIteratorTest extends RealIteratorTestCase
{
/**
* @dataProvider getAcceptData
*/
public function testAccept($mode, $expected)
{
$inner = new InnerTypeIterator(self::$files);
$iterator = new FileTypeFilterIterator($inner, $mode);
$this->assertIterator($expected, $iterator);
}
public function getAcceptData()
{
$onlyFiles = [
'test.py',
'foo/bar.tmp',
'test.php',
'.bar',
'.foo/.bar',
'.foo/bar',
'foo bar',
];
$onlyDirectories = [
'.git',
'foo',
'toto',
'toto/.git',
'.foo',
];
return [
[FileTypeFilterIterator::ONLY_FILES, $this->toAbsolute($onlyFiles)],
[FileTypeFilterIterator::ONLY_DIRECTORIES, $this->toAbsolute($onlyDirectories)],
];
}
}
class InnerTypeIterator extends \ArrayIterator
{
public function current()
{
return new \SplFileInfo(parent::current());
}
public function isFile()
{
return $this->current()->isFile();
}
public function isDir()
{
return $this->current()->isDir();
}
}

View File

@@ -0,0 +1,86 @@
<?php
/*
* This file is part of the Symfony package.
*
* (c) Fabien Potencier <fabien@symfony.com>
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*/
namespace Symfony\Component\Finder\Tests\Iterator;
use Symfony\Component\Finder\Iterator\FilecontentFilterIterator;
class FilecontentFilterIteratorTest extends IteratorTestCase
{
public function testAccept()
{
$inner = new MockFileListIterator(['test.txt']);
$iterator = new FilecontentFilterIterator($inner, [], []);
$this->assertIterator(['test.txt'], $iterator);
}
public function testDirectory()
{
$inner = new MockFileListIterator(['directory']);
$iterator = new FilecontentFilterIterator($inner, ['directory'], []);
$this->assertIterator([], $iterator);
}
public function testUnreadableFile()
{
$inner = new MockFileListIterator(['file r-']);
$iterator = new FilecontentFilterIterator($inner, ['file r-'], []);
$this->assertIterator([], $iterator);
}
/**
* @dataProvider getTestFilterData
*/
public function testFilter(\Iterator $inner, array $matchPatterns, array $noMatchPatterns, array $resultArray)
{
$iterator = new FilecontentFilterIterator($inner, $matchPatterns, $noMatchPatterns);
$this->assertIterator($resultArray, $iterator);
}
public function getTestFilterData()
{
$inner = new MockFileListIterator();
$inner[] = new MockSplFileInfo([
'name' => 'a.txt',
'contents' => 'Lorem ipsum...',
'type' => 'file',
'mode' => 'r+', ]
);
$inner[] = new MockSplFileInfo([
'name' => 'b.yml',
'contents' => 'dolor sit...',
'type' => 'file',
'mode' => 'r+', ]
);
$inner[] = new MockSplFileInfo([
'name' => 'some/other/dir/third.php',
'contents' => 'amet...',
'type' => 'file',
'mode' => 'r+', ]
);
$inner[] = new MockSplFileInfo([
'name' => 'unreadable-file.txt',
'contents' => false,
'type' => 'file',
'mode' => 'r+', ]
);
return [
[$inner, ['.'], [], ['a.txt', 'b.yml', 'some/other/dir/third.php']],
[$inner, ['ipsum'], [], ['a.txt']],
[$inner, ['i', 'amet'], ['Lorem', 'amet'], ['b.yml']],
];
}
}

View File

@@ -0,0 +1,54 @@
<?php
/*
* This file is part of the Symfony package.
*
* (c) Fabien Potencier <fabien@symfony.com>
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*/
namespace Symfony\Component\Finder\Tests\Iterator;
use Symfony\Component\Finder\Iterator\FilenameFilterIterator;
class FilenameFilterIteratorTest extends IteratorTestCase
{
/**
* @dataProvider getAcceptData
*/
public function testAccept($matchPatterns, $noMatchPatterns, $expected)
{
$inner = new InnerNameIterator(['test.php', 'test.py', 'foo.php']);
$iterator = new FilenameFilterIterator($inner, $matchPatterns, $noMatchPatterns);
$this->assertIterator($expected, $iterator);
}
public function getAcceptData()
{
return [
[['test.*'], [], ['test.php', 'test.py']],
[[], ['test.*'], ['foo.php']],
[['*.php'], ['test.*'], ['foo.php']],
[['*.php', '*.py'], ['foo.*'], ['test.php', 'test.py']],
[['/\.php$/'], [], ['test.php', 'foo.php']],
[[], ['/\.php$/'], ['test.py']],
];
}
}
class InnerNameIterator extends \ArrayIterator
{
public function current()
{
return new \SplFileInfo(parent::current());
}
public function getFilename()
{
return parent::current();
}
}

View File

@@ -0,0 +1,53 @@
<?php
/*
* This file is part of the Symfony package.
*
* (c) Fabien Potencier <fabien@symfony.com>
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*/
namespace Symfony\Component\Finder\Tests\Iterator;
/**
* @author Alex Bogomazov
*
* @group legacy
*/
class FilterIteratorTest extends RealIteratorTestCase
{
public function testFilterFilesystemIterators()
{
$i = new \FilesystemIterator($this->toAbsolute());
// it is expected that there are test.py test.php in the tmpDir
$i = $this->getMockForAbstractClass('Symfony\Component\Finder\Iterator\FilterIterator', [$i]);
$i->expects($this->any())
->method('accept')
->willReturnCallback(function () use ($i) {
return (bool) preg_match('/\.php/', (string) $i->current());
}
);
$c = 0;
foreach ($i as $item) {
++$c;
}
$this->assertEquals(1, $c);
$i->rewind();
$c = 0;
foreach ($i as $item) {
++$c;
}
// This would fail in php older than 5.5.23/5.6.7 with \FilterIterator
// but works with Symfony\Component\Finder\Iterator\FilterIterator
// see https://bugs.php.net/68557
$this->assertEquals(1, $c);
}
}

View File

@@ -0,0 +1,55 @@
<?php
/*
* This file is part of the Symfony package.
*
* (c) Fabien Potencier <fabien@symfony.com>
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*/
namespace Symfony\Component\Finder\Tests\Iterator;
class Iterator implements \Iterator
{
protected $values = [];
public function __construct(array $values = [])
{
foreach ($values as $value) {
$this->attach(new \SplFileInfo($value));
}
$this->rewind();
}
public function attach(\SplFileInfo $fileinfo)
{
$this->values[] = $fileinfo;
}
public function rewind()
{
reset($this->values);
}
public function valid()
{
return false !== $this->current();
}
public function next()
{
next($this->values);
}
public function current()
{
return current($this->values);
}
public function key()
{
return key($this->values);
}
}

View File

@@ -0,0 +1,93 @@
<?php
/*
* This file is part of the Symfony package.
*
* (c) Fabien Potencier <fabien@symfony.com>
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*/
namespace Symfony\Component\Finder\Tests\Iterator;
use PHPUnit\Framework\TestCase;
abstract class IteratorTestCase extends TestCase
{
protected function assertIterator($expected, \Traversable $iterator)
{
// set iterator_to_array $use_key to false to avoid values merge
// this made FinderTest::testAppendWithAnArray() fail with GnuFinderAdapter
$values = array_map(function (\SplFileInfo $fileinfo) { return str_replace('/', \DIRECTORY_SEPARATOR, $fileinfo->getPathname()); }, iterator_to_array($iterator, false));
$expected = array_map(function ($path) { return str_replace('/', \DIRECTORY_SEPARATOR, $path); }, $expected);
sort($values);
sort($expected);
$this->assertEquals($expected, array_values($values));
}
protected function assertOrderedIterator($expected, \Traversable $iterator)
{
$values = array_map(function (\SplFileInfo $fileinfo) { return $fileinfo->getPathname(); }, iterator_to_array($iterator));
$this->assertEquals($expected, array_values($values));
}
/**
* Same as assertOrderedIterator, but checks the order of groups of
* array elements.
*
* @param array $expected - an array of arrays. For any two subarrays
* $a and $b such that $a goes before $b in $expected, the method
* asserts that any element of $a goes before any element of $b
* in the sequence generated by $iterator
*/
protected function assertOrderedIteratorForGroups(array $expected, \Traversable $iterator)
{
$values = array_values(array_map(function (\SplFileInfo $fileinfo) { return $fileinfo->getPathname(); }, iterator_to_array($iterator)));
foreach ($expected as $subarray) {
$temp = [];
while (\count($values) && \count($temp) < \count($subarray)) {
$temp[] = array_shift($values);
}
sort($temp);
sort($subarray);
$this->assertEquals($subarray, $temp);
}
}
/**
* Same as IteratorTestCase::assertIterator with foreach usage.
*/
protected function assertIteratorInForeach(array $expected, \Traversable $iterator)
{
$values = [];
foreach ($iterator as $file) {
$this->assertInstanceOf('Symfony\\Component\\Finder\\SplFileInfo', $file);
$values[] = $file->getPathname();
}
sort($values);
sort($expected);
$this->assertEquals($expected, array_values($values));
}
/**
* Same as IteratorTestCase::assertOrderedIterator with foreach usage.
*/
protected function assertOrderedIteratorInForeach(array $expected, \Traversable $iterator)
{
$values = [];
foreach ($iterator as $file) {
$this->assertInstanceOf('Symfony\\Component\\Finder\\SplFileInfo', $file);
$values[] = $file->getPathname();
}
$this->assertEquals($expected, array_values($values));
}
}

View File

@@ -0,0 +1,21 @@
<?php
/*
* This file is part of the Symfony package.
*
* (c) Fabien Potencier <fabien@symfony.com>
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*/
namespace Symfony\Component\Finder\Tests\Iterator;
class MockFileListIterator extends \ArrayIterator
{
public function __construct(array $filesArray = [])
{
$files = array_map(function ($file) { return new MockSplFileInfo($file); }, $filesArray);
parent::__construct($files);
}
}

View File

@@ -0,0 +1,132 @@
<?php
/*
* This file is part of the Symfony package.
*
* (c) Fabien Potencier <fabien@symfony.com>
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*/
namespace Symfony\Component\Finder\Tests\Iterator;
class MockSplFileInfo extends \SplFileInfo
{
const TYPE_DIRECTORY = 1;
const TYPE_FILE = 2;
const TYPE_UNKNOWN = 3;
private $contents = null;
private $mode = null;
private $type = null;
private $relativePath = null;
private $relativePathname = null;
public function __construct($param)
{
if (\is_string($param)) {
parent::__construct($param);
} elseif (\is_array($param)) {
$defaults = [
'name' => 'file.txt',
'contents' => null,
'mode' => null,
'type' => null,
'relativePath' => null,
'relativePathname' => null,
];
$defaults = array_merge($defaults, $param);
parent::__construct($defaults['name']);
$this->setContents($defaults['contents']);
$this->setMode($defaults['mode']);
$this->setType($defaults['type']);
$this->setRelativePath($defaults['relativePath']);
$this->setRelativePathname($defaults['relativePathname']);
} else {
throw new \RuntimeException(sprintf('Incorrect parameter "%s"', $param));
}
}
public function isFile()
{
if (null === $this->type) {
return false !== strpos($this->getFilename(), 'file');
}
return self::TYPE_FILE === $this->type;
}
public function isDir()
{
if (null === $this->type) {
return false !== strpos($this->getFilename(), 'directory');
}
return self::TYPE_DIRECTORY === $this->type;
}
public function isReadable()
{
if (null === $this->mode) {
return preg_match('/r\+/', $this->getFilename());
}
return preg_match('/r\+/', $this->mode);
}
public function getContents()
{
return $this->contents;
}
public function setContents($contents)
{
$this->contents = $contents;
}
public function setMode($mode)
{
$this->mode = $mode;
}
public function setType($type)
{
if (\is_string($type)) {
switch ($type) {
case 'directory':
case 'd':
$this->type = self::TYPE_DIRECTORY;
break;
case 'file':
case 'f':
$this->type = self::TYPE_FILE;
break;
default:
$this->type = self::TYPE_UNKNOWN;
}
} else {
$this->type = $type;
}
}
public function setRelativePath($relativePath)
{
$this->relativePath = $relativePath;
}
public function setRelativePathname($relativePathname)
{
$this->relativePathname = $relativePathname;
}
public function getRelativePath()
{
return $this->relativePath;
}
public function getRelativePathname()
{
return $this->relativePathname;
}
}

View File

@@ -0,0 +1,71 @@
<?php
/*
* This file is part of the Symfony package.
*
* (c) Fabien Potencier <fabien@symfony.com>
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*/
namespace Symfony\Component\Finder\Tests\Iterator;
use PHPUnit\Framework\TestCase;
use Symfony\Component\Finder\Iterator\MultiplePcreFilterIterator;
class MultiplePcreFilterIteratorTest extends TestCase
{
/**
* @dataProvider getIsRegexFixtures
*/
public function testIsRegex($string, $isRegex, $message)
{
$testIterator = new TestMultiplePcreFilterIterator();
$this->assertEquals($isRegex, $testIterator->isRegex($string), $message);
}
public function getIsRegexFixtures()
{
return [
['foo', false, 'string'],
[' foo ', false, '" " is not a valid delimiter'],
['\\foo\\', false, '"\\" is not a valid delimiter'],
['afooa', false, '"a" is not a valid delimiter'],
['//', false, 'the pattern should contain at least 1 character'],
['/a/', true, 'valid regex'],
['/foo/', true, 'valid regex'],
['/foo/i', true, 'valid regex with a single modifier'],
['/foo/imsxu', true, 'valid regex with multiple modifiers'],
['#foo#', true, '"#" is a valid delimiter'],
['{foo}', true, '"{,}" is a valid delimiter pair'],
['[foo]', true, '"[,]" is a valid delimiter pair'],
['(foo)', true, '"(,)" is a valid delimiter pair'],
['<foo>', true, '"<,>" is a valid delimiter pair'],
['*foo.*', false, '"*" is not considered as a valid delimiter'],
['?foo.?', false, '"?" is not considered as a valid delimiter'],
];
}
}
class TestMultiplePcreFilterIterator extends MultiplePcreFilterIterator
{
public function __construct()
{
}
public function accept()
{
throw new \BadFunctionCallException('Not implemented');
}
public function isRegex($str)
{
return parent::isRegex($str);
}
public function toRegex($str)
{
throw new \BadFunctionCallException('Not implemented');
}
}

View File

@@ -0,0 +1,82 @@
<?php
/*
* This file is part of the Symfony package.
*
* (c) Fabien Potencier <fabien@symfony.com>
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*/
namespace Symfony\Component\Finder\Tests\Iterator;
use Symfony\Component\Finder\Iterator\PathFilterIterator;
class PathFilterIteratorTest extends IteratorTestCase
{
/**
* @dataProvider getTestFilterData
*/
public function testFilter(\Iterator $inner, array $matchPatterns, array $noMatchPatterns, array $resultArray)
{
$iterator = new PathFilterIterator($inner, $matchPatterns, $noMatchPatterns);
$this->assertIterator($resultArray, $iterator);
}
public function getTestFilterData()
{
$inner = new MockFileListIterator();
//PATH: A/B/C/abc.dat
$inner[] = new MockSplFileInfo([
'name' => 'abc.dat',
'relativePathname' => 'A'.\DIRECTORY_SEPARATOR.'B'.\DIRECTORY_SEPARATOR.'C'.\DIRECTORY_SEPARATOR.'abc.dat',
]);
//PATH: A/B/ab.dat
$inner[] = new MockSplFileInfo([
'name' => 'ab.dat',
'relativePathname' => 'A'.\DIRECTORY_SEPARATOR.'B'.\DIRECTORY_SEPARATOR.'ab.dat',
]);
//PATH: A/a.dat
$inner[] = new MockSplFileInfo([
'name' => 'a.dat',
'relativePathname' => 'A'.\DIRECTORY_SEPARATOR.'a.dat',
]);
//PATH: copy/A/B/C/abc.dat.copy
$inner[] = new MockSplFileInfo([
'name' => 'abc.dat.copy',
'relativePathname' => 'copy'.\DIRECTORY_SEPARATOR.'A'.\DIRECTORY_SEPARATOR.'B'.\DIRECTORY_SEPARATOR.'C'.\DIRECTORY_SEPARATOR.'abc.dat',
]);
//PATH: copy/A/B/ab.dat.copy
$inner[] = new MockSplFileInfo([
'name' => 'ab.dat.copy',
'relativePathname' => 'copy'.\DIRECTORY_SEPARATOR.'A'.\DIRECTORY_SEPARATOR.'B'.\DIRECTORY_SEPARATOR.'ab.dat',
]);
//PATH: copy/A/a.dat.copy
$inner[] = new MockSplFileInfo([
'name' => 'a.dat.copy',
'relativePathname' => 'copy'.\DIRECTORY_SEPARATOR.'A'.\DIRECTORY_SEPARATOR.'a.dat',
]);
return [
[$inner, ['/^A/'], [], ['abc.dat', 'ab.dat', 'a.dat']],
[$inner, ['/^A\/B/'], [], ['abc.dat', 'ab.dat']],
[$inner, ['/^A\/B\/C/'], [], ['abc.dat']],
[$inner, ['/A\/B\/C/'], [], ['abc.dat', 'abc.dat.copy']],
[$inner, ['A'], [], ['abc.dat', 'ab.dat', 'a.dat', 'abc.dat.copy', 'ab.dat.copy', 'a.dat.copy']],
[$inner, ['A/B'], [], ['abc.dat', 'ab.dat', 'abc.dat.copy', 'ab.dat.copy']],
[$inner, ['A/B/C'], [], ['abc.dat', 'abc.dat.copy']],
[$inner, ['copy/A'], [], ['abc.dat.copy', 'ab.dat.copy', 'a.dat.copy']],
[$inner, ['copy/A/B'], [], ['abc.dat.copy', 'ab.dat.copy']],
[$inner, ['copy/A/B/C'], [], ['abc.dat.copy']],
];
}
}

View File

@@ -0,0 +1,119 @@
<?php
/*
* This file is part of the Symfony package.
*
* (c) Fabien Potencier <fabien@symfony.com>
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*/
namespace Symfony\Component\Finder\Tests\Iterator;
abstract class RealIteratorTestCase extends IteratorTestCase
{
protected static $tmpDir;
protected static $files;
public static function setUpBeforeClass()
{
self::$tmpDir = realpath(sys_get_temp_dir()).\DIRECTORY_SEPARATOR.'symfony_finder';
self::$files = [
'.git/',
'.foo/',
'.foo/.bar',
'.foo/bar',
'.bar',
'test.py',
'foo/',
'foo/bar.tmp',
'test.php',
'toto/',
'toto/.git/',
'foo bar',
];
self::$files = self::toAbsolute(self::$files);
if (is_dir(self::$tmpDir)) {
self::tearDownAfterClass();
} else {
mkdir(self::$tmpDir);
}
foreach (self::$files as $file) {
if (\DIRECTORY_SEPARATOR === $file[\strlen($file) - 1]) {
mkdir($file);
} else {
touch($file);
}
}
file_put_contents(self::toAbsolute('test.php'), str_repeat(' ', 800));
file_put_contents(self::toAbsolute('test.py'), str_repeat(' ', 2000));
touch(self::toAbsolute('foo/bar.tmp'), strtotime('2005-10-15'));
touch(self::toAbsolute('test.php'), strtotime('2005-10-15'));
}
public static function tearDownAfterClass()
{
$paths = new \RecursiveIteratorIterator(
new \RecursiveDirectoryIterator(self::$tmpDir, \RecursiveDirectoryIterator::SKIP_DOTS),
\RecursiveIteratorIterator::CHILD_FIRST
);
foreach ($paths as $path) {
if ($path->isDir()) {
if ($path->isLink()) {
@unlink($path);
} else {
@rmdir($path);
}
} else {
@unlink($path);
}
}
}
protected static function toAbsolute($files = null)
{
/*
* Without the call to setUpBeforeClass() property can be null.
*/
if (!self::$tmpDir) {
self::$tmpDir = realpath(sys_get_temp_dir()).\DIRECTORY_SEPARATOR.'symfony_finder';
}
if (\is_array($files)) {
$f = [];
foreach ($files as $file) {
if (\is_array($file)) {
$f[] = self::toAbsolute($file);
} else {
$f[] = self::$tmpDir.\DIRECTORY_SEPARATOR.str_replace('/', \DIRECTORY_SEPARATOR, $file);
}
}
return $f;
}
if (\is_string($files)) {
return self::$tmpDir.\DIRECTORY_SEPARATOR.str_replace('/', \DIRECTORY_SEPARATOR, $files);
}
return self::$tmpDir;
}
protected static function toAbsoluteFixtures($files)
{
$f = [];
foreach ($files as $file) {
$f[] = realpath(__DIR__.\DIRECTORY_SEPARATOR.'..'.\DIRECTORY_SEPARATOR.'Fixtures'.\DIRECTORY_SEPARATOR.$file);
}
return $f;
}
}

View File

@@ -0,0 +1,59 @@
<?php
/*
* This file is part of the Symfony package.
*
* (c) Fabien Potencier <fabien@symfony.com>
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*/
namespace Symfony\Component\Finder\Tests\Iterator;
use Symfony\Component\Finder\Iterator\RecursiveDirectoryIterator;
class RecursiveDirectoryIteratorTest extends IteratorTestCase
{
/**
* @group network
*/
public function testRewindOnFtp()
{
try {
$i = new RecursiveDirectoryIterator('ftp://speedtest.tele2.net/', \RecursiveDirectoryIterator::SKIP_DOTS);
} catch (\UnexpectedValueException $e) {
$this->markTestSkipped('Unsupported stream "ftp".');
}
$i->rewind();
$this->assertTrue(true);
}
/**
* @group network
*/
public function testSeekOnFtp()
{
try {
$i = new RecursiveDirectoryIterator('ftp://speedtest.tele2.net/', \RecursiveDirectoryIterator::SKIP_DOTS);
} catch (\UnexpectedValueException $e) {
$this->markTestSkipped('Unsupported stream "ftp".');
}
$contains = [
'ftp://speedtest.tele2.net'.\DIRECTORY_SEPARATOR.'1000GB.zip',
'ftp://speedtest.tele2.net'.\DIRECTORY_SEPARATOR.'100GB.zip',
];
$actual = [];
$i->seek(0);
$actual[] = $i->getPathname();
$i->seek(1);
$actual[] = $i->getPathname();
$this->assertEquals($contains, $actual);
}
}

View File

@@ -0,0 +1,69 @@
<?php
/*
* This file is part of the Symfony package.
*
* (c) Fabien Potencier <fabien@symfony.com>
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*/
namespace Symfony\Component\Finder\Tests\Iterator;
use Symfony\Component\Finder\Comparator\NumberComparator;
use Symfony\Component\Finder\Iterator\SizeRangeFilterIterator;
class SizeRangeFilterIteratorTest extends RealIteratorTestCase
{
/**
* @dataProvider getAcceptData
*/
public function testAccept($size, $expected)
{
$inner = new InnerSizeIterator(self::$files);
$iterator = new SizeRangeFilterIterator($inner, $size);
$this->assertIterator($expected, $iterator);
}
public function getAcceptData()
{
$lessThan1KGreaterThan05K = [
'.foo',
'.git',
'foo',
'test.php',
'toto',
'toto/.git',
];
return [
[[new NumberComparator('< 1K'), new NumberComparator('> 0.5K')], $this->toAbsolute($lessThan1KGreaterThan05K)],
];
}
}
class InnerSizeIterator extends \ArrayIterator
{
public function current()
{
return new \SplFileInfo(parent::current());
}
public function getFilename()
{
return parent::current();
}
public function isFile()
{
return $this->current()->isFile();
}
public function getSize()
{
return $this->current()->getSize();
}
}

View File

@@ -0,0 +1,179 @@
<?php
/*
* This file is part of the Symfony package.
*
* (c) Fabien Potencier <fabien@symfony.com>
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*/
namespace Symfony\Component\Finder\Tests\Iterator;
use Symfony\Component\Finder\Iterator\SortableIterator;
class SortableIteratorTest extends RealIteratorTestCase
{
public function testConstructor()
{
try {
new SortableIterator(new Iterator([]), 'foobar');
$this->fail('__construct() throws an \InvalidArgumentException exception if the mode is not valid');
} catch (\Exception $e) {
$this->assertInstanceOf('InvalidArgumentException', $e, '__construct() throws an \InvalidArgumentException exception if the mode is not valid');
}
}
/**
* @dataProvider getAcceptData
*/
public function testAccept($mode, $expected)
{
if (!\is_callable($mode)) {
switch ($mode) {
case SortableIterator::SORT_BY_ACCESSED_TIME:
touch(self::toAbsolute('.git'));
sleep(1);
file_get_contents(self::toAbsolute('.bar'));
break;
case SortableIterator::SORT_BY_CHANGED_TIME:
file_put_contents(self::toAbsolute('test.php'), 'foo');
sleep(1);
file_put_contents(self::toAbsolute('test.py'), 'foo');
break;
case SortableIterator::SORT_BY_MODIFIED_TIME:
file_put_contents(self::toAbsolute('test.php'), 'foo');
sleep(1);
file_put_contents(self::toAbsolute('test.py'), 'foo');
break;
}
}
$inner = new Iterator(self::$files);
$iterator = new SortableIterator($inner, $mode);
if (SortableIterator::SORT_BY_ACCESSED_TIME === $mode
|| SortableIterator::SORT_BY_CHANGED_TIME === $mode
|| SortableIterator::SORT_BY_MODIFIED_TIME === $mode
) {
if ('\\' === \DIRECTORY_SEPARATOR && SortableIterator::SORT_BY_MODIFIED_TIME !== $mode) {
$this->markTestSkipped('Sorting by atime or ctime is not supported on Windows');
}
$this->assertOrderedIteratorForGroups($expected, $iterator);
} else {
$this->assertOrderedIterator($expected, $iterator);
}
}
public function getAcceptData()
{
$sortByName = [
'.bar',
'.foo',
'.foo/.bar',
'.foo/bar',
'.git',
'foo',
'foo bar',
'foo/bar.tmp',
'test.php',
'test.py',
'toto',
'toto/.git',
];
$sortByType = [
'.foo',
'.git',
'foo',
'toto',
'toto/.git',
'.bar',
'.foo/.bar',
'.foo/bar',
'foo bar',
'foo/bar.tmp',
'test.php',
'test.py',
];
$customComparison = [
'.bar',
'.foo',
'.foo/.bar',
'.foo/bar',
'.git',
'foo',
'foo bar',
'foo/bar.tmp',
'test.php',
'test.py',
'toto',
'toto/.git',
];
$sortByAccessedTime = [
// For these two files the access time was set to 2005-10-15
['foo/bar.tmp', 'test.php'],
// These files were created more or less at the same time
[
'.git',
'.foo',
'.foo/.bar',
'.foo/bar',
'test.py',
'foo',
'toto',
'toto/.git',
'foo bar',
],
// This file was accessed after sleeping for 1 sec
['.bar'],
];
$sortByChangedTime = [
[
'.git',
'.foo',
'.foo/.bar',
'.foo/bar',
'.bar',
'foo',
'foo/bar.tmp',
'toto',
'toto/.git',
'foo bar',
],
['test.php'],
['test.py'],
];
$sortByModifiedTime = [
[
'.git',
'.foo',
'.foo/.bar',
'.foo/bar',
'.bar',
'foo',
'foo/bar.tmp',
'toto',
'toto/.git',
'foo bar',
],
['test.php'],
['test.py'],
];
return [
[SortableIterator::SORT_BY_NAME, $this->toAbsolute($sortByName)],
[SortableIterator::SORT_BY_TYPE, $this->toAbsolute($sortByType)],
[SortableIterator::SORT_BY_ACCESSED_TIME, $this->toAbsolute($sortByAccessedTime)],
[SortableIterator::SORT_BY_CHANGED_TIME, $this->toAbsolute($sortByChangedTime)],
[SortableIterator::SORT_BY_MODIFIED_TIME, $this->toAbsolute($sortByModifiedTime)],
[function (\SplFileInfo $a, \SplFileInfo $b) { return strcmp($a->getRealPath(), $b->getRealPath()); }, $this->toAbsolute($customComparison)],
];
}
}