[Finder] fluid, calling in() not required after append()
This commit is contained in:
parent
0c6e145c0d
commit
cc0be8edf2
@ -615,8 +615,8 @@ class Finder implements \IteratorAggregate, \Countable
|
|||||||
*/
|
*/
|
||||||
public function getIterator()
|
public function getIterator()
|
||||||
{
|
{
|
||||||
if (0 === count($this->dirs)) {
|
if (0 === count($this->dirs) && 0 === count($this->iterators)) {
|
||||||
throw new \LogicException('You must call the in() method before iterating over a Finder.');
|
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)) {
|
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.
|
* The set can be another Finder, an Iterator, an IteratorAggregate, or even a plain array.
|
||||||
*
|
*
|
||||||
* @param mixed $iterator
|
* @param mixed $iterator
|
||||||
|
*
|
||||||
|
* @return Finder The finder
|
||||||
|
*
|
||||||
|
* @throws \InvalidArgumentException When the given argument is not iterable.
|
||||||
*/
|
*/
|
||||||
public function append($iterator)
|
public function append($iterator)
|
||||||
{
|
{
|
||||||
@ -657,6 +661,8 @@ class Finder implements \IteratorAggregate, \Countable
|
|||||||
} else {
|
} else {
|
||||||
throw new \InvalidArgumentException('Finder::append() method wrong argument type.');
|
throw new \InvalidArgumentException('Finder::append() method wrong argument type.');
|
||||||
}
|
}
|
||||||
|
|
||||||
|
return $this;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -408,7 +408,8 @@ class FinderTest extends Iterator\RealIteratorTestCase
|
|||||||
$finder1 = $this->buildFinder($adapter);
|
$finder1 = $this->buildFinder($adapter);
|
||||||
$finder1->directories()->in(self::$tmpDir);
|
$finder1->directories()->in(self::$tmpDir);
|
||||||
|
|
||||||
$finder->append($finder1);
|
$finder = $finder->append($finder1);
|
||||||
|
|
||||||
|
|
||||||
$this->assertIterator($this->toAbsolute(array('foo', 'foo/bar.tmp', 'toto')), $finder->getIterator());
|
$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());
|
$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()
|
public function testCountDirectories()
|
||||||
{
|
{
|
||||||
$finder = new Finder();
|
$finder = new Finder();
|
||||||
|
Reference in New Issue
Block a user