Skip to content

Commit

Permalink
Merge pull request #2 from juniwalk/master
Browse files Browse the repository at this point in the history
Finder: implement Countable
  • Loading branch information
dg committed Feb 17, 2015
2 parents 4f2ff4f + f76258f commit 0eba793
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 1 deletion.
12 changes: 11 additions & 1 deletion src/Finder/Finder.php
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@
*
* @author David Grudl
*/
class Finder extends Nette\Object implements \IteratorAggregate
class Finder extends Nette\Object implements \IteratorAggregate, \Countable
{
/** @var array */
private $paths = array();
Expand Down Expand Up @@ -187,6 +187,16 @@ private static function buildPattern($masks)
/********************* iterator generator ****************d*g**/


/**
* Get the number of found files and/or directories.
* @return int
*/
public function count()
{
return iterator_count($this->getIterator());
}


/**
* Returns iterator.
* @return \Iterator
Expand Down
6 changes: 6 additions & 0 deletions tests/Finder/Finder.basic.phpt
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,12 @@ function export($iterator)
}


test(function() { // count the results
$finder = Finder::findFiles('file.txt')->in('files');
Assert::count(1, $finder);
});


test(function() { // non-recursive file search
$finder = Finder::findFiles('file.txt')->in('files');
Assert::same(array('files/file.txt'), export($finder));
Expand Down

0 comments on commit 0eba793

Please sign in to comment.