Skip to content

Commit

Permalink
Add a method to check if any results were found
Browse files Browse the repository at this point in the history
  • Loading branch information
duncan3dc committed Sep 26, 2017
1 parent 985b478 commit e5f4d26
Show file tree
Hide file tree
Showing 3 changed files with 29 additions and 0 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Expand Up @@ -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
-----
Expand Down
14 changes: 14 additions & 0 deletions Finder.php
Expand Up @@ -613,6 +613,20 @@ public function append($iterator)
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.
*
Expand Down
14 changes: 14 additions & 0 deletions Tests/FinderTest.php
Expand Up @@ -424,6 +424,20 @@ public function testCountWithoutIn()
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
*/
Expand Down

0 comments on commit e5f4d26

Please sign in to comment.