Add a method to check if any results were found
This commit is contained in:
parent
07f79737bc
commit
24dcb5202c
@ -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
|
||||
-----
|
||||
|
@ -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.
|
||||
*
|
||||
|
@ -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
|
||||
*/
|
||||
|
Reference in New Issue
Block a user