Merge branch '2.3' into 2.7

* 2.3:
  [Finder] Fix recursive filter iterator
  Improve the structure of the Finder testsuite

Conflicts:
	src/Symfony/Component/Finder/Iterator/ExcludeDirectoryFilterIterator.php
	src/Symfony/Component/Finder/Tests/FinderTest.php
	src/Symfony/Component/Finder/Tests/Iterator/DateRangeFilterIteratorTest.php
This commit is contained in:
Nicolas Grekas 2015-09-18 09:19:55 +02:00
commit 666f523984
13 changed files with 258 additions and 305 deletions

View File

@ -16,8 +16,9 @@ namespace Symfony\Component\Finder\Iterator;
* *
* @author Fabien Potencier <fabien@symfony.com> * @author Fabien Potencier <fabien@symfony.com>
*/ */
class ExcludeDirectoryFilterIterator extends FilterIterator class ExcludeDirectoryFilterIterator extends FilterIterator implements \RecursiveIterator
{ {
private $isRecursive;
private $patterns = array(); private $patterns = array();
/** /**
@ -28,6 +29,7 @@ class ExcludeDirectoryFilterIterator extends FilterIterator
*/ */
public function __construct(\Iterator $iterator, array $directories) public function __construct(\Iterator $iterator, array $directories)
{ {
$this->isRecursive = $iterator instanceof \RecursiveIterator;
foreach ($directories as $directory) { foreach ($directories as $directory) {
$this->patterns[] = '#(^|/)'.preg_quote($directory, '#').'(/|$)#'; $this->patterns[] = '#(^|/)'.preg_quote($directory, '#').'(/|$)#';
} }
@ -52,4 +54,17 @@ class ExcludeDirectoryFilterIterator extends FilterIterator
return true; return true;
} }
public function hasChildren()
{
return $this->isRecursive && $this->getInnerIterator()->hasChildren();
}
public function getChildren()
{
$children = new self($this->getInnerIterator()->getChildren(), array());
$children->patterns = $this->patterns;
return $children;
}
} }

View File

@ -18,18 +18,8 @@ namespace Symfony\Component\Finder\Iterator;
* *
* @author Alex Bogomazov * @author Alex Bogomazov
*/ */
abstract class FilterIterator extends \FilterIterator implements \RecursiveIterator abstract class FilterIterator extends \FilterIterator
{ {
public function hasChildren()
{
return $this->getInnerIterator() instanceof \RecursiveIterator && $this->getInnerIterator()->hasChildren();
}
public function getChildren()
{
return $this->getInnerIterator()->getChildren();
}
/** /**
* This is a workaround for the problem with \FilterIterator leaving inner \FilesystemIterator in wrong state after * This is a workaround for the problem with \FilterIterator leaving inner \FilesystemIterator in wrong state after
* rewind in some cases. * rewind in some cases.

View File

@ -0,0 +1,28 @@
<?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\Adapter\BsdFindAdapter;
class BsdFinderTest extends FinderTest
{
protected function getAdapter()
{
$adapter = new BsdFindAdapter();
if (!$adapter->isSupported()) {
$this->markTestSkipped(get_class($adapter).' is not supported.');
}
return $adapter;
}
}

View File

@ -11,8 +11,10 @@
namespace Symfony\Component\Finder\Tests; namespace Symfony\Component\Finder\Tests;
use Symfony\Component\Finder\Adapter\AdapterInterface;
use Symfony\Component\Finder\Adapter\GnuFindAdapter;
use Symfony\Component\Finder\Adapter\PhpAdapter;
use Symfony\Component\Finder\Finder; use Symfony\Component\Finder\Finder;
use Symfony\Component\Finder\Adapter;
class FinderTest extends Iterator\RealIteratorTestCase class FinderTest extends Iterator\RealIteratorTestCase
{ {
@ -21,109 +23,94 @@ class FinderTest extends Iterator\RealIteratorTestCase
$this->assertInstanceOf('Symfony\Component\Finder\Finder', Finder::create()); $this->assertInstanceOf('Symfony\Component\Finder\Finder', Finder::create());
} }
/** public function testDirectories()
* @dataProvider getAdaptersTestData
*/
public function testDirectories($adapter)
{ {
$finder = $this->buildFinder($adapter); $finder = $this->buildFinder();
$this->assertSame($finder, $finder->directories()); $this->assertSame($finder, $finder->directories());
$this->assertIterator($this->toAbsolute(array('foo', 'toto')), $finder->in(self::$tmpDir)->getIterator()); $this->assertIterator($this->toAbsolute(array('foo', 'toto')), $finder->in(self::$tmpDir)->getIterator());
$finder = $this->buildFinder($adapter); $finder = $this->buildFinder();
$finder->directories(); $finder->directories();
$finder->files(); $finder->files();
$finder->directories(); $finder->directories();
$this->assertIterator($this->toAbsolute(array('foo', 'toto')), $finder->in(self::$tmpDir)->getIterator()); $this->assertIterator($this->toAbsolute(array('foo', 'toto')), $finder->in(self::$tmpDir)->getIterator());
} }
/** public function testFiles()
* @dataProvider getAdaptersTestData
*/
public function testFiles($adapter)
{ {
$finder = $this->buildFinder($adapter); $finder = $this->buildFinder();
$this->assertSame($finder, $finder->files()); $this->assertSame($finder, $finder->files());
$this->assertIterator($this->toAbsolute(array('foo/bar.tmp', 'test.php', 'test.py', 'foo bar')), $finder->in(self::$tmpDir)->getIterator()); $this->assertIterator($this->toAbsolute(array('foo/bar.tmp', 'test.php', 'test.py', 'foo bar')), $finder->in(self::$tmpDir)->getIterator());
$finder = $this->buildFinder($adapter); $finder = $this->buildFinder();
$finder->files(); $finder->files();
$finder->directories(); $finder->directories();
$finder->files(); $finder->files();
$this->assertIterator($this->toAbsolute(array('foo/bar.tmp', 'test.php', 'test.py', 'foo bar')), $finder->in(self::$tmpDir)->getIterator()); $this->assertIterator($this->toAbsolute(array('foo/bar.tmp', 'test.php', 'test.py', 'foo bar')), $finder->in(self::$tmpDir)->getIterator());
} }
/** public function testDepth()
* @dataProvider getAdaptersTestData
*/
public function testDepth($adapter)
{ {
$finder = $this->buildFinder($adapter); $finder = $this->buildFinder();
$this->assertSame($finder, $finder->depth('< 1')); $this->assertSame($finder, $finder->depth('< 1'));
$this->assertIterator($this->toAbsolute(array('foo', 'test.php', 'test.py', 'toto', 'foo bar')), $finder->in(self::$tmpDir)->getIterator()); $this->assertIterator($this->toAbsolute(array('foo', 'test.php', 'test.py', 'toto', 'foo bar')), $finder->in(self::$tmpDir)->getIterator());
$finder = $this->buildFinder($adapter); $finder = $this->buildFinder();
$this->assertSame($finder, $finder->depth('<= 0')); $this->assertSame($finder, $finder->depth('<= 0'));
$this->assertIterator($this->toAbsolute(array('foo', 'test.php', 'test.py', 'toto', 'foo bar')), $finder->in(self::$tmpDir)->getIterator()); $this->assertIterator($this->toAbsolute(array('foo', 'test.php', 'test.py', 'toto', 'foo bar')), $finder->in(self::$tmpDir)->getIterator());
$finder = $this->buildFinder($adapter); $finder = $this->buildFinder();
$this->assertSame($finder, $finder->depth('>= 1')); $this->assertSame($finder, $finder->depth('>= 1'));
$this->assertIterator($this->toAbsolute(array('foo/bar.tmp')), $finder->in(self::$tmpDir)->getIterator()); $this->assertIterator($this->toAbsolute(array('foo/bar.tmp')), $finder->in(self::$tmpDir)->getIterator());
$finder = $this->buildFinder($adapter); $finder = $this->buildFinder();
$finder->depth('< 1')->depth('>= 1'); $finder->depth('< 1')->depth('>= 1');
$this->assertIterator(array(), $finder->in(self::$tmpDir)->getIterator()); $this->assertIterator(array(), $finder->in(self::$tmpDir)->getIterator());
} }
/** public function testName()
* @dataProvider getAdaptersTestData
*/
public function testName($adapter)
{ {
$finder = $this->buildFinder($adapter); $finder = $this->buildFinder();
$this->assertSame($finder, $finder->name('*.php')); $this->assertSame($finder, $finder->name('*.php'));
$this->assertIterator($this->toAbsolute(array('test.php')), $finder->in(self::$tmpDir)->getIterator()); $this->assertIterator($this->toAbsolute(array('test.php')), $finder->in(self::$tmpDir)->getIterator());
$finder = $this->buildFinder($adapter); $finder = $this->buildFinder();
$finder->name('test.ph*'); $finder->name('test.ph*');
$finder->name('test.py'); $finder->name('test.py');
$this->assertIterator($this->toAbsolute(array('test.php', 'test.py')), $finder->in(self::$tmpDir)->getIterator()); $this->assertIterator($this->toAbsolute(array('test.php', 'test.py')), $finder->in(self::$tmpDir)->getIterator());
$finder = $this->buildFinder($adapter); $finder = $this->buildFinder();
$finder->name('~^test~i'); $finder->name('~^test~i');
$this->assertIterator($this->toAbsolute(array('test.php', 'test.py')), $finder->in(self::$tmpDir)->getIterator()); $this->assertIterator($this->toAbsolute(array('test.php', 'test.py')), $finder->in(self::$tmpDir)->getIterator());
$finder = $this->buildFinder($adapter); $finder = $this->buildFinder();
$finder->name('~\\.php$~i'); $finder->name('~\\.php$~i');
$this->assertIterator($this->toAbsolute(array('test.php')), $finder->in(self::$tmpDir)->getIterator()); $this->assertIterator($this->toAbsolute(array('test.php')), $finder->in(self::$tmpDir)->getIterator());
$finder = $this->buildFinder($adapter); $finder = $this->buildFinder();
$finder->name('test.p{hp,y}'); $finder->name('test.p{hp,y}');
$this->assertIterator($this->toAbsolute(array('test.php', 'test.py')), $finder->in(self::$tmpDir)->getIterator()); $this->assertIterator($this->toAbsolute(array('test.php', 'test.py')), $finder->in(self::$tmpDir)->getIterator());
} }
/** public function testNotName()
* @dataProvider getAdaptersTestData
*/
public function testNotName($adapter)
{ {
$finder = $this->buildFinder($adapter); $finder = $this->buildFinder();
$this->assertSame($finder, $finder->notName('*.php')); $this->assertSame($finder, $finder->notName('*.php'));
$this->assertIterator($this->toAbsolute(array('foo', 'foo/bar.tmp', 'test.py', 'toto', 'foo bar')), $finder->in(self::$tmpDir)->getIterator()); $this->assertIterator($this->toAbsolute(array('foo', 'foo/bar.tmp', 'test.py', 'toto', 'foo bar')), $finder->in(self::$tmpDir)->getIterator());
$finder = $this->buildFinder($adapter); $finder = $this->buildFinder();
$finder->notName('*.php'); $finder->notName('*.php');
$finder->notName('*.py'); $finder->notName('*.py');
$this->assertIterator($this->toAbsolute(array('foo', 'foo/bar.tmp', 'toto', 'foo bar')), $finder->in(self::$tmpDir)->getIterator()); $this->assertIterator($this->toAbsolute(array('foo', 'foo/bar.tmp', 'toto', 'foo bar')), $finder->in(self::$tmpDir)->getIterator());
$finder = $this->buildFinder($adapter); $finder = $this->buildFinder();
$finder->name('test.ph*'); $finder->name('test.ph*');
$finder->name('test.py'); $finder->name('test.py');
$finder->notName('*.php'); $finder->notName('*.php');
$finder->notName('*.py'); $finder->notName('*.py');
$this->assertIterator(array(), $finder->in(self::$tmpDir)->getIterator()); $this->assertIterator(array(), $finder->in(self::$tmpDir)->getIterator());
$finder = $this->buildFinder($adapter); $finder = $this->buildFinder();
$finder->name('test.ph*'); $finder->name('test.ph*');
$finder->name('test.py'); $finder->name('test.py');
$finder->notName('*.p{hp,y}'); $finder->notName('*.p{hp,y}');
@ -133,228 +120,186 @@ class FinderTest extends Iterator\RealIteratorTestCase
/** /**
* @dataProvider getRegexNameTestData * @dataProvider getRegexNameTestData
*/ */
public function testRegexName($adapter, $regex) public function testRegexName($regex)
{ {
$finder = $this->buildFinder($adapter); $finder = $this->buildFinder();
$finder->name($regex); $finder->name($regex);
$this->assertIterator($this->toAbsolute(array('test.py', 'test.php')), $finder->in(self::$tmpDir)->getIterator()); $this->assertIterator($this->toAbsolute(array('test.py', 'test.php')), $finder->in(self::$tmpDir)->getIterator());
} }
/** public function testSize()
* @dataProvider getAdaptersTestData
*/
public function testSize($adapter)
{ {
$finder = $this->buildFinder($adapter); $finder = $this->buildFinder();
$this->assertSame($finder, $finder->files()->size('< 1K')->size('> 500')); $this->assertSame($finder, $finder->files()->size('< 1K')->size('> 500'));
$this->assertIterator($this->toAbsolute(array('test.php')), $finder->in(self::$tmpDir)->getIterator()); $this->assertIterator($this->toAbsolute(array('test.php')), $finder->in(self::$tmpDir)->getIterator());
} }
/** public function testDate()
* @dataProvider getAdaptersTestData
*/
public function testDate($adapter)
{ {
$finder = $this->buildFinder($adapter); $finder = $this->buildFinder();
$this->assertSame($finder, $finder->files()->date('until last month')); $this->assertSame($finder, $finder->files()->date('until last month'));
$this->assertIterator($this->toAbsolute(array('foo/bar.tmp', 'test.php')), $finder->in(self::$tmpDir)->getIterator()); $this->assertIterator($this->toAbsolute(array('foo/bar.tmp', 'test.php')), $finder->in(self::$tmpDir)->getIterator());
} }
/** public function testExclude()
* @dataProvider getAdaptersTestData
*/
public function testExclude($adapter)
{ {
$finder = $this->buildFinder($adapter); $finder = $this->buildFinder();
$this->assertSame($finder, $finder->exclude('foo')); $this->assertSame($finder, $finder->exclude('foo'));
$this->assertIterator($this->toAbsolute(array('test.php', 'test.py', 'toto', 'foo bar')), $finder->in(self::$tmpDir)->getIterator()); $this->assertIterator($this->toAbsolute(array('test.php', 'test.py', 'toto', 'foo bar')), $finder->in(self::$tmpDir)->getIterator());
} }
/** public function testIgnoreVCS()
* @dataProvider getAdaptersTestData
*/
public function testIgnoreVCS($adapter)
{ {
$finder = $this->buildFinder($adapter); $finder = $this->buildFinder();
$this->assertSame($finder, $finder->ignoreVCS(false)->ignoreDotFiles(false)); $this->assertSame($finder, $finder->ignoreVCS(false)->ignoreDotFiles(false));
$this->assertIterator($this->toAbsolute(array('.git', 'foo', 'foo/bar.tmp', 'test.php', 'test.py', 'toto', '.bar', '.foo', '.foo/.bar', '.foo/bar', 'foo bar')), $finder->in(self::$tmpDir)->getIterator()); $this->assertIterator($this->toAbsolute(array('.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($adapter); $finder = $this->buildFinder();
$finder->ignoreVCS(false)->ignoreVCS(false)->ignoreDotFiles(false); $finder->ignoreVCS(false)->ignoreVCS(false)->ignoreDotFiles(false);
$this->assertIterator($this->toAbsolute(array('.git', 'foo', 'foo/bar.tmp', 'test.php', 'test.py', 'toto', '.bar', '.foo', '.foo/.bar', '.foo/bar', 'foo bar')), $finder->in(self::$tmpDir)->getIterator()); $this->assertIterator($this->toAbsolute(array('.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($adapter); $finder = $this->buildFinder();
$this->assertSame($finder, $finder->ignoreVCS(true)->ignoreDotFiles(false)); $this->assertSame($finder, $finder->ignoreVCS(true)->ignoreDotFiles(false));
$this->assertIterator($this->toAbsolute(array('foo', 'foo/bar.tmp', 'test.php', 'test.py', 'toto', '.bar', '.foo', '.foo/.bar', '.foo/bar', 'foo bar')), $finder->in(self::$tmpDir)->getIterator()); $this->assertIterator($this->toAbsolute(array('foo', 'foo/bar.tmp', 'test.php', 'test.py', 'toto', '.bar', '.foo', '.foo/.bar', '.foo/bar', 'foo bar')), $finder->in(self::$tmpDir)->getIterator());
} }
/** public function testIgnoreDotFiles()
* @dataProvider getAdaptersTestData
*/
public function testIgnoreDotFiles($adapter)
{ {
$finder = $this->buildFinder($adapter); $finder = $this->buildFinder();
$this->assertSame($finder, $finder->ignoreDotFiles(false)->ignoreVCS(false)); $this->assertSame($finder, $finder->ignoreDotFiles(false)->ignoreVCS(false));
$this->assertIterator($this->toAbsolute(array('.git', '.bar', '.foo', '.foo/.bar', '.foo/bar', 'foo', 'foo/bar.tmp', 'test.php', 'test.py', 'toto', 'foo bar')), $finder->in(self::$tmpDir)->getIterator()); $this->assertIterator($this->toAbsolute(array('.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($adapter); $finder = $this->buildFinder();
$finder->ignoreDotFiles(false)->ignoreDotFiles(false)->ignoreVCS(false); $finder->ignoreDotFiles(false)->ignoreDotFiles(false)->ignoreVCS(false);
$this->assertIterator($this->toAbsolute(array('.git', '.bar', '.foo', '.foo/.bar', '.foo/bar', 'foo', 'foo/bar.tmp', 'test.php', 'test.py', 'toto', 'foo bar')), $finder->in(self::$tmpDir)->getIterator()); $this->assertIterator($this->toAbsolute(array('.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($adapter); $finder = $this->buildFinder();
$this->assertSame($finder, $finder->ignoreDotFiles(true)->ignoreVCS(false)); $this->assertSame($finder, $finder->ignoreDotFiles(true)->ignoreVCS(false));
$this->assertIterator($this->toAbsolute(array('foo', 'foo/bar.tmp', 'test.php', 'test.py', 'toto', 'foo bar')), $finder->in(self::$tmpDir)->getIterator()); $this->assertIterator($this->toAbsolute(array('foo', 'foo/bar.tmp', 'test.php', 'test.py', 'toto', 'foo bar')), $finder->in(self::$tmpDir)->getIterator());
} }
/** public function testSortByName()
* @dataProvider getAdaptersTestData
*/
public function testSortByName($adapter)
{ {
$finder = $this->buildFinder($adapter); $finder = $this->buildFinder();
$this->assertSame($finder, $finder->sortByName()); $this->assertSame($finder, $finder->sortByName());
$this->assertIterator($this->toAbsolute(array('foo', 'foo bar', 'foo/bar.tmp', 'test.php', 'test.py', 'toto')), $finder->in(self::$tmpDir)->getIterator()); $this->assertIterator($this->toAbsolute(array('foo', 'foo bar', 'foo/bar.tmp', 'test.php', 'test.py', 'toto')), $finder->in(self::$tmpDir)->getIterator());
} }
/** public function testSortByType()
* @dataProvider getAdaptersTestData
*/
public function testSortByType($adapter)
{ {
$finder = $this->buildFinder($adapter); $finder = $this->buildFinder();
$this->assertSame($finder, $finder->sortByType()); $this->assertSame($finder, $finder->sortByType());
$this->assertIterator($this->toAbsolute(array('foo', 'foo bar', 'toto', 'foo/bar.tmp', 'test.php', 'test.py')), $finder->in(self::$tmpDir)->getIterator()); $this->assertIterator($this->toAbsolute(array('foo', 'foo bar', 'toto', 'foo/bar.tmp', 'test.php', 'test.py')), $finder->in(self::$tmpDir)->getIterator());
} }
/** public function testSortByAccessedTime()
* @dataProvider getAdaptersTestData
*/
public function testSortByAccessedTime($adapter)
{ {
$finder = $this->buildFinder($adapter); $finder = $this->buildFinder();
$this->assertSame($finder, $finder->sortByAccessedTime()); $this->assertSame($finder, $finder->sortByAccessedTime());
$this->assertIterator($this->toAbsolute(array('foo/bar.tmp', 'test.php', 'toto', 'test.py', 'foo', 'foo bar')), $finder->in(self::$tmpDir)->getIterator()); $this->assertIterator($this->toAbsolute(array('foo/bar.tmp', 'test.php', 'toto', 'test.py', 'foo', 'foo bar')), $finder->in(self::$tmpDir)->getIterator());
} }
/** public function testSortByChangedTime()
* @dataProvider getAdaptersTestData
*/
public function testSortByChangedTime($adapter)
{ {
$finder = $this->buildFinder($adapter); $finder = $this->buildFinder();
$this->assertSame($finder, $finder->sortByChangedTime()); $this->assertSame($finder, $finder->sortByChangedTime());
$this->assertIterator($this->toAbsolute(array('toto', 'test.py', 'test.php', 'foo/bar.tmp', 'foo', 'foo bar')), $finder->in(self::$tmpDir)->getIterator()); $this->assertIterator($this->toAbsolute(array('toto', 'test.py', 'test.php', 'foo/bar.tmp', 'foo', 'foo bar')), $finder->in(self::$tmpDir)->getIterator());
} }
/** public function testSortByModifiedTime()
* @dataProvider getAdaptersTestData
*/
public function testSortByModifiedTime($adapter)
{ {
$finder = $this->buildFinder($adapter); $finder = $this->buildFinder();
$this->assertSame($finder, $finder->sortByModifiedTime()); $this->assertSame($finder, $finder->sortByModifiedTime());
$this->assertIterator($this->toAbsolute(array('foo/bar.tmp', 'test.php', 'toto', 'test.py', 'foo', 'foo bar')), $finder->in(self::$tmpDir)->getIterator()); $this->assertIterator($this->toAbsolute(array('foo/bar.tmp', 'test.php', 'toto', 'test.py', 'foo', 'foo bar')), $finder->in(self::$tmpDir)->getIterator());
} }
/** public function testSort()
* @dataProvider getAdaptersTestData
*/
public function testSort($adapter)
{ {
$finder = $this->buildFinder($adapter); $finder = $this->buildFinder();
$this->assertSame($finder, $finder->sort(function (\SplFileInfo $a, \SplFileInfo $b) { return strcmp($a->getRealPath(), $b->getRealPath()); })); $this->assertSame($finder, $finder->sort(function (\SplFileInfo $a, \SplFileInfo $b) { return strcmp($a->getRealPath(), $b->getRealPath()); }));
$this->assertIterator($this->toAbsolute(array('foo', 'foo bar', 'foo/bar.tmp', 'test.php', 'test.py', 'toto')), $finder->in(self::$tmpDir)->getIterator()); $this->assertIterator($this->toAbsolute(array('foo', 'foo bar', 'foo/bar.tmp', 'test.php', 'test.py', 'toto')), $finder->in(self::$tmpDir)->getIterator());
} }
/** public function testFilter()
* @dataProvider getAdaptersTestData
*/
public function testFilter($adapter)
{ {
$finder = $this->buildFinder($adapter); $finder = $this->buildFinder();
$this->assertSame($finder, $finder->filter(function (\SplFileInfo $f) { return false !== strpos($f, 'test'); })); $this->assertSame($finder, $finder->filter(function (\SplFileInfo $f) { return false !== strpos($f, 'test'); }));
$this->assertIterator($this->toAbsolute(array('test.php', 'test.py')), $finder->in(self::$tmpDir)->getIterator()); $this->assertIterator($this->toAbsolute(array('test.php', 'test.py')), $finder->in(self::$tmpDir)->getIterator());
} }
/** public function testFollowLinks()
* @dataProvider getAdaptersTestData
*/
public function testFollowLinks($adapter)
{ {
if ('\\' == DIRECTORY_SEPARATOR) { if ('\\' == DIRECTORY_SEPARATOR) {
return; $this->markTestSkipped('symlinks are not supported on Windows');
} }
$finder = $this->buildFinder($adapter); $finder = $this->buildFinder();
$this->assertSame($finder, $finder->followLinks()); $this->assertSame($finder, $finder->followLinks());
$this->assertIterator($this->toAbsolute(array('foo', 'foo/bar.tmp', 'test.php', 'test.py', 'toto', 'foo bar')), $finder->in(self::$tmpDir)->getIterator()); $this->assertIterator($this->toAbsolute(array('foo', 'foo/bar.tmp', 'test.php', 'test.py', 'toto', 'foo bar')), $finder->in(self::$tmpDir)->getIterator());
} }
/** public function testIn()
* @dataProvider getAdaptersTestData
*/
public function testIn($adapter)
{ {
$finder = $this->buildFinder($adapter); $finder = $this->buildFinder();
try {
$finder->in('foobar');
$this->fail('->in() throws a \InvalidArgumentException if the directory does not exist');
} catch (\Exception $e) {
$this->assertInstanceOf('InvalidArgumentException', $e, '->in() throws a \InvalidArgumentException if the directory does not exist');
}
$finder = $this->buildFinder($adapter);
$iterator = $finder->files()->name('*.php')->depth('< 1')->in(array(self::$tmpDir, __DIR__))->getIterator(); $iterator = $finder->files()->name('*.php')->depth('< 1')->in(array(self::$tmpDir, __DIR__))->getIterator();
$this->assertIterator(array(self::$tmpDir.DIRECTORY_SEPARATOR.'test.php', __DIR__.DIRECTORY_SEPARATOR.'FinderTest.php', __DIR__.DIRECTORY_SEPARATOR.'GlobTest.php'), $iterator); $expected = array(
self::$tmpDir.DIRECTORY_SEPARATOR.'test.php',
__DIR__.DIRECTORY_SEPARATOR.'BsdFinderTest.php',
__DIR__.DIRECTORY_SEPARATOR.'FinderTest.php',
__DIR__.DIRECTORY_SEPARATOR.'GnuFinderTest.php',
__DIR__.DIRECTORY_SEPARATOR.'GlobTest.php',
);
$this->assertIterator($expected, $iterator);
} }
/** /**
* @dataProvider getAdaptersTestData * @expectedException \InvalidArgumentException
*/ */
public function testInWithGlob($adapter) public function testInWithNonExistentDirectory()
{ {
$finder = $this->buildFinder($adapter); $finder = new Finder();
$finder->in('foobar');
}
public function testInWithGlob()
{
$finder = $this->buildFinder();
$finder->in(array(__DIR__.'/Fixtures/*/B/C', __DIR__.'/Fixtures/*/*/B/C'))->getIterator(); $finder->in(array(__DIR__.'/Fixtures/*/B/C', __DIR__.'/Fixtures/*/*/B/C'))->getIterator();
$this->assertIterator($this->toAbsoluteFixtures(array('A/B/C/abc.dat', 'copy/A/B/C/abc.dat.copy')), $finder); $this->assertIterator($this->toAbsoluteFixtures(array('A/B/C/abc.dat', 'copy/A/B/C/abc.dat.copy')), $finder);
} }
/** /**
* @dataProvider getAdaptersTestData
* @expectedException \InvalidArgumentException * @expectedException \InvalidArgumentException
*/ */
public function testInWithNonDirectoryGlob($adapter) public function testInWithNonDirectoryGlob()
{ {
$finder = $this->buildFinder($adapter); $finder = new Finder();
$finder->in(__DIR__.'/Fixtures/A/a*'); $finder->in(__DIR__.'/Fixtures/A/a*');
} }
/** public function testInWithGlobBrace()
* @dataProvider getAdaptersTestData
*/
public function testInWithGlobBrace($adapter)
{ {
$finder = $this->buildFinder($adapter); $finder = $this->buildFinder();
$finder->in(array(__DIR__.'/Fixtures/{A,copy/A}/B/C'))->getIterator(); $finder->in(array(__DIR__.'/Fixtures/{A,copy/A}/B/C'))->getIterator();
$this->assertIterator($this->toAbsoluteFixtures(array('A/B/C/abc.dat', 'copy/A/B/C/abc.dat.copy')), $finder); $this->assertIterator($this->toAbsoluteFixtures(array('A/B/C/abc.dat', 'copy/A/B/C/abc.dat.copy')), $finder);
} }
/** /**
* @dataProvider getAdaptersTestData * @expectedException \LogicException
*/ */
public function testGetIterator($adapter) public function testGetIteratorWithoutIn()
{ {
$finder = $this->buildFinder($adapter); $finder = Finder::create();
try {
$finder->getIterator(); $finder->getIterator();
$this->fail('->getIterator() throws a \LogicException if the in() method has not been called');
} catch (\Exception $e) {
$this->assertInstanceOf('LogicException', $e, '->getIterator() throws a \LogicException if the in() method has not been called');
} }
$finder = $this->buildFinder($adapter); public function testGetIterator()
{
$finder = $this->buildFinder();
$dirs = array(); $dirs = array();
foreach ($finder->directories()->in(self::$tmpDir) as $dir) { foreach ($finder->directories()->in(self::$tmpDir) as $dir) {
$dirs[] = (string) $dir; $dirs[] = (string) $dir;
@ -367,22 +312,19 @@ class FinderTest extends Iterator\RealIteratorTestCase
$this->assertEquals($expected, $dirs, 'implements the \IteratorAggregate interface'); $this->assertEquals($expected, $dirs, 'implements the \IteratorAggregate interface');
$finder = $this->buildFinder($adapter); $finder = $this->buildFinder();
$this->assertEquals(2, iterator_count($finder->directories()->in(self::$tmpDir)), 'implements the \IteratorAggregate interface'); $this->assertEquals(2, iterator_count($finder->directories()->in(self::$tmpDir)), 'implements the \IteratorAggregate interface');
$finder = $this->buildFinder($adapter); $finder = $this->buildFinder();
$a = iterator_to_array($finder->directories()->in(self::$tmpDir)); $a = iterator_to_array($finder->directories()->in(self::$tmpDir));
$a = array_values(array_map(function ($a) { return (string) $a; }, $a)); $a = array_values(array_map(function ($a) { return (string) $a; }, $a));
sort($a); sort($a);
$this->assertEquals($expected, $a, 'implements the \IteratorAggregate interface'); $this->assertEquals($expected, $a, 'implements the \IteratorAggregate interface');
} }
/** public function testRelativePath()
* @dataProvider getAdaptersTestData
*/
public function testRelativePath($adapter)
{ {
$finder = $this->buildFinder($adapter)->in(self::$tmpDir); $finder = $this->buildFinder()->in(self::$tmpDir);
$paths = array(); $paths = array();
@ -398,12 +340,9 @@ class FinderTest extends Iterator\RealIteratorTestCase
$this->assertEquals($ref, $paths); $this->assertEquals($ref, $paths);
} }
/** public function testRelativePathname()
* @dataProvider getAdaptersTestData
*/
public function testRelativePathname($adapter)
{ {
$finder = $this->buildFinder($adapter)->in(self::$tmpDir)->sortByName(); $finder = $this->buildFinder()->in(self::$tmpDir)->sortByName();
$paths = array(); $paths = array();
@ -419,15 +358,12 @@ class FinderTest extends Iterator\RealIteratorTestCase
$this->assertEquals($ref, $paths); $this->assertEquals($ref, $paths);
} }
/** public function testAppendWithAFinder()
* @dataProvider getAdaptersTestData
*/
public function testAppendWithAFinder($adapter)
{ {
$finder = $this->buildFinder($adapter); $finder = $this->buildFinder();
$finder->files()->in(self::$tmpDir.DIRECTORY_SEPARATOR.'foo'); $finder->files()->in(self::$tmpDir.DIRECTORY_SEPARATOR.'foo');
$finder1 = $this->buildFinder($adapter); $finder1 = $this->buildFinder();
$finder1->directories()->in(self::$tmpDir); $finder1->directories()->in(self::$tmpDir);
$finder = $finder->append($finder1); $finder = $finder->append($finder1);
@ -435,12 +371,9 @@ class FinderTest extends Iterator\RealIteratorTestCase
$this->assertIterator($this->toAbsolute(array('foo', 'foo/bar.tmp', 'toto')), $finder->getIterator()); $this->assertIterator($this->toAbsolute(array('foo', 'foo/bar.tmp', 'toto')), $finder->getIterator());
} }
/** public function testAppendWithAnArray()
* @dataProvider getAdaptersTestData
*/
public function testAppendWithAnArray($adapter)
{ {
$finder = $this->buildFinder($adapter); $finder = $this->buildFinder();
$finder->files()->in(self::$tmpDir.DIRECTORY_SEPARATOR.'foo'); $finder->files()->in(self::$tmpDir.DIRECTORY_SEPARATOR.'foo');
$finder->append($this->toAbsolute(array('foo', 'toto'))); $finder->append($this->toAbsolute(array('foo', 'toto')));
@ -448,20 +381,14 @@ class FinderTest extends Iterator\RealIteratorTestCase
$this->assertIterator($this->toAbsolute(array('foo', 'foo/bar.tmp', 'toto')), $finder->getIterator()); $this->assertIterator($this->toAbsolute(array('foo', 'foo/bar.tmp', 'toto')), $finder->getIterator());
} }
/** public function testAppendReturnsAFinder()
* @dataProvider getAdaptersTestData
*/
public function testAppendReturnsAFinder($adapter)
{ {
$this->assertInstanceOf('Symfony\\Component\\Finder\\Finder', $this->buildFinder($adapter)->append(array())); $this->assertInstanceOf('Symfony\\Component\\Finder\\Finder', Finder::create()->append(array()));
} }
/** public function testAppendDoesNotRequireIn()
* @dataProvider getAdaptersTestData
*/
public function testAppendDoesNotRequireIn($adapter)
{ {
$finder = $this->buildFinder($adapter); $finder = $this->buildFinder();
$finder->in(self::$tmpDir.DIRECTORY_SEPARATOR.'foo'); $finder->in(self::$tmpDir.DIRECTORY_SEPARATOR.'foo');
$finder1 = Finder::create()->append($finder); $finder1 = Finder::create()->append($finder);
@ -505,9 +432,9 @@ class FinderTest extends Iterator\RealIteratorTestCase
/** /**
* @dataProvider getContainsTestData * @dataProvider getContainsTestData
*/ */
public function testContains($adapter, $matchPatterns, $noMatchPatterns, $expected) public function testContains($matchPatterns, $noMatchPatterns, $expected)
{ {
$finder = $this->buildFinder($adapter); $finder = $this->buildFinder();
$finder->in(__DIR__.DIRECTORY_SEPARATOR.'Fixtures') $finder->in(__DIR__.DIRECTORY_SEPARATOR.'Fixtures')
->name('*.txt')->sortByName() ->name('*.txt')->sortByName()
->contains($matchPatterns) ->contains($matchPatterns)
@ -516,12 +443,9 @@ class FinderTest extends Iterator\RealIteratorTestCase
$this->assertIterator($this->toAbsoluteFixtures($expected), $finder); $this->assertIterator($this->toAbsoluteFixtures($expected), $finder);
} }
/** public function testContainsOnDirectory()
* @dataProvider getAdaptersTestData
*/
public function testContainsOnDirectory(Adapter\AdapterInterface $adapter)
{ {
$finder = $this->buildFinder($adapter); $finder = $this->buildFinder();
$finder->in(__DIR__) $finder->in(__DIR__)
->directories() ->directories()
->name('Fixtures') ->name('Fixtures')
@ -529,12 +453,9 @@ class FinderTest extends Iterator\RealIteratorTestCase
$this->assertIterator(array(), $finder); $this->assertIterator(array(), $finder);
} }
/** public function testNotContainsOnDirectory()
* @dataProvider getAdaptersTestData
*/
public function testNotContainsOnDirectory(Adapter\AdapterInterface $adapter)
{ {
$finder = $this->buildFinder($adapter); $finder = $this->buildFinder();
$finder->in(__DIR__) $finder->in(__DIR__)
->directories() ->directories()
->name('Fixtures') ->name('Fixtures')
@ -547,10 +468,8 @@ class FinderTest extends Iterator\RealIteratorTestCase
* with inner FilesystemIterator in an invalid state. * with inner FilesystemIterator in an invalid state.
* *
* @see https://bugs.php.net/bug.php?id=49104 * @see https://bugs.php.net/bug.php?id=49104
*
* @dataProvider getAdaptersTestData
*/ */
public function testMultipleLocations(Adapter\AdapterInterface $adapter) public function testMultipleLocations()
{ {
$locations = array( $locations = array(
self::$tmpDir.'/', self::$tmpDir.'/',
@ -558,31 +477,52 @@ class FinderTest extends Iterator\RealIteratorTestCase
); );
// it is expected that there are test.py test.php in the tmpDir // it is expected that there are test.py test.php in the tmpDir
$finder = $this->buildFinder($adapter); $finder = $this->buildFinder();
$finder->in($locations)->depth('< 1')->name('test.php'); $finder->in($locations)->depth('< 1')->name('test.php');
$this->assertCount(1, $finder); $this->assertCount(1, $finder);
} }
/** /**
* Iterator keys must be the file pathname. * Searching in multiple locations with sub directories involves
* AppendIterator which does an unnecessary rewind which leaves
* FilterIterator with inner FilesystemIterator in an invalid state.
* *
* @dataProvider getAdaptersTestData * @see https://bugs.php.net/bug.php?id=49104
*/ */
public function testIteratorKeys(Adapter\AdapterInterface $adapter) public function testMultipleLocationsWithSubDirectories()
{ {
$finder = $this->buildFinder($adapter)->in(self::$tmpDir); $locations = array(
__DIR__.'/Fixtures/one',
self::$tmpDir.DIRECTORY_SEPARATOR.'toto',
);
$finder = $this->buildFinder();
$finder->in($locations)->depth('< 10')->name('*.neon');
$expected = array(
__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) { foreach ($finder as $key => $file) {
$this->assertEquals($file->getPathname(), $key); $this->assertEquals($file->getPathname(), $key);
} }
} }
/** public function testRegexSpecialCharsLocationWithPathRestrictionContainingStartFlag()
* @dataProvider getAdaptersTestData
*/
public function testRegexSpecialCharsLocationWithPathRestrictionContainingStartFlag(Adapter\AdapterInterface $adapter)
{ {
$finder = $this->buildFinder($adapter); $finder = $this->buildFinder();
$finder->in(__DIR__.DIRECTORY_SEPARATOR.'Fixtures'.DIRECTORY_SEPARATOR.'r+e.gex[c]a(r)s') $finder->in(__DIR__.DIRECTORY_SEPARATOR.'Fixtures'.DIRECTORY_SEPARATOR.'r+e.gex[c]a(r)s')
->path('/^dir/'); ->path('/^dir/');
@ -603,7 +543,7 @@ class FinderTest extends Iterator\RealIteratorTestCase
$this->assertEquals( $this->assertEquals(
array('c', 'e', 'a', 'd', 'b'), array('c', 'e', 'a', 'd', 'b'),
array_map(function (Adapter\AdapterInterface $adapter) { array_map(function (AdapterInterface $adapter) {
return $adapter->getName(); return $adapter->getName();
}, $finder->getAdapters()) }, $finder->getAdapters())
); );
@ -626,17 +566,9 @@ class FinderTest extends Iterator\RealIteratorTestCase
$this->assertIterator($filenames, $finder->in(sys_get_temp_dir())->getIterator()); $this->assertIterator($filenames, $finder->in(sys_get_temp_dir())->getIterator());
} }
public function getAdaptersTestData()
{
return array_map(
function ($adapter) { return array($adapter); },
$this->getValidAdapters()
);
}
public function getContainsTestData() public function getContainsTestData()
{ {
$tests = array( return array(
array('', '', array()), array('', '', array()),
array('foo', 'bar', array()), array('foo', 'bar', array()),
array('', 'foobar', array('dolor.txt', 'ipsum.txt', 'lorem.txt')), array('', 'foobar', array('dolor.txt', 'ipsum.txt', 'lorem.txt')),
@ -648,26 +580,22 @@ class FinderTest extends Iterator\RealIteratorTestCase
array('', 'lorem', array('dolor.txt', 'ipsum.txt')), array('', 'lorem', array('dolor.txt', 'ipsum.txt')),
array('ipsum dolor sit amet', '/^IPSUM/m', array('lorem.txt')), array('ipsum dolor sit amet', '/^IPSUM/m', array('lorem.txt')),
); );
return $this->buildTestData($tests);
} }
public function getRegexNameTestData() public function getRegexNameTestData()
{ {
$tests = array( return array(
array('~.+\\.p.+~i'), array('~.+\\.p.+~i'),
array('~t.*s~i'), array('~t.*s~i'),
); );
return $this->buildTestData($tests);
} }
/** /**
* @dataProvider getTestPathData * @dataProvider getTestPathData
*/ */
public function testPath(Adapter\AdapterInterface $adapter, $matchPatterns, $noMatchPatterns, array $expected) public function testPath($matchPatterns, $noMatchPatterns, array $expected)
{ {
$finder = $this->buildFinder($adapter); $finder = $this->buildFinder();
$finder->in(__DIR__.DIRECTORY_SEPARATOR.'Fixtures') $finder->in(__DIR__.DIRECTORY_SEPARATOR.'Fixtures')
->path($matchPatterns) ->path($matchPatterns)
->notPath($noMatchPatterns); ->notPath($noMatchPatterns);
@ -679,20 +607,20 @@ class FinderTest extends Iterator\RealIteratorTestCase
{ {
// test that by default, PhpAdapter is selected // test that by default, PhpAdapter is selected
$adapters = Finder::create()->getAdapters(); $adapters = Finder::create()->getAdapters();
$this->assertTrue($adapters[0] instanceof Adapter\PhpAdapter); $this->assertTrue($adapters[0] instanceof PhpAdapter);
// test another adapter selection // test another adapter selection
$adapters = Finder::create()->setAdapter('gnu_find')->getAdapters(); $adapters = Finder::create()->setAdapter('gnu_find')->getAdapters();
$this->assertTrue($adapters[0] instanceof Adapter\GnuFindAdapter); $this->assertTrue($adapters[0] instanceof GnuFindAdapter);
// test that useBestAdapter method removes selection // test that useBestAdapter method removes selection
$adapters = Finder::create()->useBestAdapter()->getAdapters(); $adapters = Finder::create()->useBestAdapter()->getAdapters();
$this->assertFalse($adapters[0] instanceof Adapter\PhpAdapter); $this->assertFalse($adapters[0] instanceof PhpAdapter);
} }
public function getTestPathData() public function getTestPathData()
{ {
$tests = array( return array(
array('', '', array()), array('', '', array()),
array('/^A\/B\/C/', '/C$/', array('/^A\/B\/C/', '/C$/',
array('A'.DIRECTORY_SEPARATOR.'B'.DIRECTORY_SEPARATOR.'C'.DIRECTORY_SEPARATOR.'abc.dat'), array('A'.DIRECTORY_SEPARATOR.'B'.DIRECTORY_SEPARATOR.'C'.DIRECTORY_SEPARATOR.'abc.dat'),
@ -733,20 +661,15 @@ class FinderTest extends Iterator\RealIteratorTestCase
), ),
), ),
); );
return $this->buildTestData($tests);
} }
/** public function testAccessDeniedException()
* @dataProvider getAdaptersTestData
*/
public function testAccessDeniedException(Adapter\AdapterInterface $adapter)
{ {
if ('\\' === DIRECTORY_SEPARATOR) { if ('\\' === DIRECTORY_SEPARATOR) {
$this->markTestSkipped('chmod is not supported on Windows'); $this->markTestSkipped('chmod is not supported on Windows');
} }
$finder = $this->buildFinder($adapter); $finder = $this->buildFinder();
$finder->files()->in(self::$tmpDir); $finder->files()->in(self::$tmpDir);
// make 'foo' directory non-readable // make 'foo' directory non-readable
@ -776,16 +699,13 @@ class FinderTest extends Iterator\RealIteratorTestCase
} }
} }
/** public function testIgnoredAccessDeniedException()
* @dataProvider getAdaptersTestData
*/
public function testIgnoredAccessDeniedException(Adapter\AdapterInterface $adapter)
{ {
if ('\\' === DIRECTORY_SEPARATOR) { if ('\\' === DIRECTORY_SEPARATOR) {
$this->markTestSkipped('chmod is not supported on Windows'); $this->markTestSkipped('chmod is not supported on Windows');
} }
$finder = $this->buildFinder($adapter); $finder = $this->buildFinder();
$finder->files()->ignoreUnreadableDirs()->in(self::$tmpDir); $finder->files()->ignoreUnreadableDirs()->in(self::$tmpDir);
// make 'foo' directory non-readable // make 'foo' directory non-readable
@ -805,62 +725,18 @@ class FinderTest extends Iterator\RealIteratorTestCase
} }
} }
private function buildTestData(array $tests) /**
* @return AdapterInterface
*/
protected function getAdapter()
{ {
$data = array(); return new PhpAdapter();
foreach ($this->getValidAdapters() as $adapter) {
foreach ($tests as $test) {
$data[] = array_merge(array($adapter), $test);
}
} }
return $data; private function buildFinder()
}
private function buildFinder(Adapter\AdapterInterface $adapter)
{ {
return Finder::create() return Finder::create()
->removeAdapters() ->removeAdapters()
->addAdapter($adapter); ->addAdapter($this->getAdapter());
}
private function getValidAdapters()
{
return array_filter(
array(
new Adapter\BsdFindAdapter(),
new Adapter\GnuFindAdapter(),
new Adapter\PhpAdapter(),
),
function (Adapter\AdapterInterface $adapter) {
return $adapter->isSupported();
}
);
}
/**
* 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/bug.php?id=49104
*/
public function testMultipleLocationsWithSubDirectories()
{
$locations = array(
__DIR__.'/Fixtures/one',
self::$tmpDir.DIRECTORY_SEPARATOR.'toto',
);
$finder = new Finder();
$finder->in($locations)->depth('< 10')->name('*.neon');
$expected = array(
__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);
} }
} }

View File

@ -0,0 +1,28 @@
<?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\Adapter\GnuFindAdapter;
class GnuFinderTest extends FinderTest
{
protected function getAdapter()
{
$adapter = new GnuFindAdapter();
if (!$adapter->isSupported()) {
$this->markTestSkipped(get_class($adapter).' is not supported.');
}
return $adapter;
}
}

View File

@ -39,6 +39,7 @@ class DateRangeFilterIteratorTest extends RealIteratorTestCase
'foo/bar.tmp', 'foo/bar.tmp',
'test.php', 'test.php',
'toto', 'toto',
'toto/.git',
'.bar', '.bar',
'.foo', '.foo',
'.foo/.bar', '.foo/.bar',
@ -51,6 +52,7 @@ class DateRangeFilterIteratorTest extends RealIteratorTestCase
'test.py', 'test.py',
'foo', 'foo',
'toto', 'toto',
'toto/.git',
'.bar', '.bar',
'.foo', '.foo',
'.foo/.bar', '.foo/.bar',

View File

@ -50,6 +50,7 @@ class DepthRangeFilterIteratorTest extends RealIteratorTestCase
'foo/bar.tmp', 'foo/bar.tmp',
'test.php', 'test.php',
'toto', 'toto',
'toto/.git',
'.foo', '.foo',
'.foo/.bar', '.foo/.bar',
'.bar', '.bar',
@ -58,12 +59,14 @@ class DepthRangeFilterIteratorTest extends RealIteratorTestCase
); );
$graterThanOrEqualTo1 = array( $graterThanOrEqualTo1 = array(
'toto/.git',
'foo/bar.tmp', 'foo/bar.tmp',
'.foo/.bar', '.foo/.bar',
'.foo/bar', '.foo/bar',
); );
$equalTo1 = array( $equalTo1 = array(
'toto/.git',
'foo/bar.tmp', 'foo/bar.tmp',
'.foo/.bar', '.foo/.bar',
'.foo/bar', '.foo/bar',

View File

@ -39,6 +39,7 @@ class ExcludeDirectoryFilterIteratorTest extends RealIteratorTestCase
'test.py', 'test.py',
'test.php', 'test.php',
'toto', 'toto',
'toto/.git',
'foo bar', 'foo bar',
); );
@ -53,6 +54,7 @@ class ExcludeDirectoryFilterIteratorTest extends RealIteratorTestCase
'foo/bar.tmp', 'foo/bar.tmp',
'test.php', 'test.php',
'toto', 'toto',
'toto/.git',
'foo bar', 'foo bar',
); );

View File

@ -43,6 +43,7 @@ class FileTypeFilterIteratorTest extends RealIteratorTestCase
'.git', '.git',
'foo', 'foo',
'toto', 'toto',
'toto/.git',
'.foo', '.foo',
); );

View File

@ -16,7 +16,7 @@ abstract class IteratorTestCase extends \PHPUnit_Framework_TestCase
protected function assertIterator($expected, \Traversable $iterator) protected function assertIterator($expected, \Traversable $iterator)
{ {
// set iterator_to_array $use_key to false to avoid values merge // set iterator_to_array $use_key to false to avoid values merge
// this made FinderTest::testAppendWithAnArray() failed with GnuFinderAdapter // 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)); $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); $expected = array_map(function ($path) { return str_replace('/', DIRECTORY_SEPARATOR, $path); }, $expected);

View File

@ -31,6 +31,7 @@ abstract class RealIteratorTestCase extends IteratorTestCase
'foo/bar.tmp', 'foo/bar.tmp',
'test.php', 'test.php',
'toto/', 'toto/',
'toto/.git/',
'foo bar', 'foo bar',
); );

View File

@ -36,6 +36,7 @@ class SizeRangeFilterIteratorTest extends RealIteratorTestCase
'foo', 'foo',
'test.php', 'test.php',
'toto', 'toto',
'toto/.git',
); );
return array( return array(

View File

@ -85,6 +85,7 @@ class SortableIteratorTest extends RealIteratorTestCase
'test.php', 'test.php',
'test.py', 'test.py',
'toto', 'toto',
'toto/.git',
); );
$sortByType = array( $sortByType = array(
@ -92,6 +93,7 @@ class SortableIteratorTest extends RealIteratorTestCase
'.git', '.git',
'foo', 'foo',
'toto', 'toto',
'toto/.git',
'.bar', '.bar',
'.foo/.bar', '.foo/.bar',
'.foo/bar', '.foo/bar',
@ -113,6 +115,7 @@ class SortableIteratorTest extends RealIteratorTestCase
'test.php', 'test.php',
'test.py', 'test.py',
'toto', 'toto',
'toto/.git',
); );
$sortByAccessedTime = array( $sortByAccessedTime = array(
@ -127,6 +130,7 @@ class SortableIteratorTest extends RealIteratorTestCase
'test.py', 'test.py',
'foo', 'foo',
'toto', 'toto',
'toto/.git',
'foo bar', 'foo bar',
), ),
// This file was accessed after sleeping for 1 sec // This file was accessed after sleeping for 1 sec
@ -143,6 +147,7 @@ class SortableIteratorTest extends RealIteratorTestCase
'foo', 'foo',
'foo/bar.tmp', 'foo/bar.tmp',
'toto', 'toto',
'toto/.git',
'foo bar', 'foo bar',
), ),
array('test.php'), array('test.php'),
@ -159,6 +164,7 @@ class SortableIteratorTest extends RealIteratorTestCase
'foo', 'foo',
'foo/bar.tmp', 'foo/bar.tmp',
'toto', 'toto',
'toto/.git',
'foo bar', 'foo bar',
), ),
array('test.php'), array('test.php'),