Skip to content
Browse files

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

  • Loading branch information...
1 parent 9e54a0d commit ff6fa8274b557953bc99b313fb718ee503922076 @vicb vicb committed Dec 10, 2012
Showing with 31 additions and 3 deletions.
  1. +8 −2 Finder.php
  2. +23 −1 Tests/FinderTest.php
View
10 Finder.php
@@ -615,8 +615,8 @@ public function in($dirs)
*/
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 @@ public function getIterator()
* 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 @@ public function append($iterator)
} else {
throw new \InvalidArgumentException('Finder::append() method wrong argument type.');
}
+
+ return $this;
}
/**
View
24 Tests/FinderTest.php
@@ -408,7 +408,8 @@ public function testAppendWithAFinder($adapter)
$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 @@ public function testAppendWithAnArray($adapter)
$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();

0 comments on commit ff6fa82

Please sign in to comment.
Something went wrong with that request. Please try again.