merged branch vicb/finder (PR #6249)

This PR was merged into the master branch.

Commits
-------

cc0be8e [Finder] fluid, calling in() not required after append()

Discussion
----------

[Finder] fluid, calling in() not required after append()
This commit is contained in:
Fabien Potencier 2012-12-10 13:39:22 +01:00
commit d63a317b21
2 changed files with 31 additions and 3 deletions

View File

@ -615,8 +615,8 @@ class Finder implements \IteratorAggregate, \Countable
*/
public function getIterator()
{
if (0 === count($this->dirs)) {
throw new \LogicException('You must call the in() method before iterating over a Finder.');
if (0 === count($this->dirs) && 0 === count($this->iterators)) {
throw new \LogicException('You must call one of in() or append() methods before iterating over a Finder.');
}
if (1 === count($this->dirs) && 0 === count($this->iterators)) {
@ -641,6 +641,10 @@ class Finder implements \IteratorAggregate, \Countable
* The set can be another Finder, an Iterator, an IteratorAggregate, or even a plain array.
*
* @param mixed $iterator
*
* @return Finder The finder
*
* @throws \InvalidArgumentException When the given argument is not iterable.
*/
public function append($iterator)
{
@ -657,6 +661,8 @@ class Finder implements \IteratorAggregate, \Countable
} else {
throw new \InvalidArgumentException('Finder::append() method wrong argument type.');
}
return $this;
}
/**

View File

@ -408,7 +408,8 @@ class FinderTest extends Iterator\RealIteratorTestCase
$finder1 = $this->buildFinder($adapter);
$finder1->directories()->in(self::$tmpDir);
$finder->append($finder1);
$finder = $finder->append($finder1);
$this->assertIterator($this->toAbsolute(array('foo', 'foo/bar.tmp', 'toto')), $finder->getIterator());
}
@ -426,6 +427,27 @@ class FinderTest extends Iterator\RealIteratorTestCase
$this->assertIterator($this->toAbsolute(array('foo', 'foo/bar.tmp', 'toto')), $finder->getIterator());
}
/**
* @dataProvider getAdaptersTestData
*/
public function testAppendReturnsAFinder($adapter)
{
$this->assertInstanceOf('Symfony\\Component\\Finder\\Finder', $this->buildFinder($adapter)->append(array()));
}
/**
* @dataProvider getAdaptersTestData
*/
public function testAppendDoesNotRequireIn($adapter)
{
$finder = $this->buildFinder($adapter);
$finder->in(self::$tmpDir.DIRECTORY_SEPARATOR.'foo');
$finder1 = Finder::create()->append($finder);
$this->assertIterator(iterator_to_array($finder->getIterator()), $finder1->getIterator());
}
public function testCountDirectories()
{
$finder = new Finder();