Skip to content

Commit

Permalink
Merge cd8cf83 into cbb0f31
Browse files Browse the repository at this point in the history
  • Loading branch information
janbarasek committed Feb 7, 2021
2 parents cbb0f31 + cd8cf83 commit b5913b2
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 0 deletions.
9 changes: 9 additions & 0 deletions src/Utils/Finder.php
Original file line number Diff line number Diff line change
Expand Up @@ -202,6 +202,15 @@ public function getIterator(): \Iterator
}


/**
* @return string[]
*/
public function getPaths(): array
{
return array_keys(iterator_to_array($this->getIterator()));
}


/**
* Returns per-path iterator.
*/
Expand Down
14 changes: 14 additions & 0 deletions tests/Utils/Finder.basic.phpt
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,20 @@ test('recursive file search', function () {
});


test('recursive file search and get paths', function () {
$finder = Finder::findFiles('file.txt')->from('files');
$pathList = $finder->getPaths();
$expectedList = [
'files/file.txt',
'files/subdir/file.txt',
'files/subdir/subdir2/file.txt',
];
sort($expectedList);
sort($pathList);
Assert::same($expectedList, $pathList);
});


test('recursive file search with depth limit', function () {
$finder = Finder::findFiles('file.txt')->from('files')->limitDepth(1);
Assert::same([
Expand Down

0 comments on commit b5913b2

Please sign in to comment.