Add a method to check if any results were found

This commit is contained in:
Craig Duncan 2017-07-10 22:30:02 +01:00
parent 07f79737bc
commit 24dcb5202c
3 changed files with 29 additions and 0 deletions

View File

@ -5,6 +5,7 @@ CHANGELOG
-----
* deprecated `Symfony\Component\Finder\Iterator\FilterIterator`
* added Finder::hasResults() method to check if any results were found
3.3.0
-----

View File

@ -613,6 +613,20 @@ class Finder implements \IteratorAggregate, \Countable
return $this;
}
/**
* Check if the any results were found.
*
* @return bool
*/
public function hasResults()
{
foreach ($this->getIterator() as $_) {
return true;
}
return false;
}
/**
* Counts all the results collected by the iterators.
*

View File

@ -424,6 +424,20 @@ class FinderTest extends Iterator\RealIteratorTestCase
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
*/