Skip to content

Commit

Permalink
Finder: collect() returns list
Browse files Browse the repository at this point in the history
  • Loading branch information
dg committed Jul 30, 2023
1 parent 0ce0601 commit 8d80a2d
Show file tree
Hide file tree
Showing 3 changed files with 6 additions and 6 deletions.
3 changes: 2 additions & 1 deletion src/Utils/Finder.php
Original file line number Diff line number Diff line change
Expand Up @@ -309,10 +309,11 @@ public function date(string $operator, string|int|\DateTimeInterface|null $date

/**
* Returns an array with all found files and directories.
* @return list<FileInfo>
*/
public function collect(): array
{
return iterator_to_array($this->getIterator());
return iterator_to_array($this->getIterator(), preserve_keys: false);
}


Expand Down
6 changes: 3 additions & 3 deletions tests/Utils/Finder.append.phpt
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ test('append finder', function () {
"fixtures.finder{$ds}subdir",
"fixtures.finder{$ds}subdir{$ds}subdir2",
"fixtures.finder{$ds}subdir{$ds}subdir2{$ds}file.txt",
], array_keys($finder->collect()));
], array_map('strval', $finder->collect()));
});

test('append files', function () {
Expand All @@ -40,7 +40,7 @@ test('append files', function () {
->append(FileSystem::unixSlashes(__DIR__));

Assert::equal([
__FILE__ => new Nette\Utils\FileInfo(__FILE__),
__DIR__ => new Nette\Utils\FileInfo(__DIR__),
new Nette\Utils\FileInfo(__FILE__),
new Nette\Utils\FileInfo(__DIR__),
], $finder->collect());
});
3 changes: 1 addition & 2 deletions tests/Utils/Finder.fileInfo.phpt
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ test('absolute path', function () {
->collect();

Assert::equal(
[__FILE__ => new FileInfo(__FILE__)],
[new FileInfo(__FILE__)],
$files,
);

Expand All @@ -36,7 +36,6 @@ test('relative path', function () {
->from('fixtures.finder')
->collect();

$files = array_values($files);
$ds = DIRECTORY_SEPARATOR;
Assert::same('subdir', $files[0]->getRelativePath());
Assert::same("subdir{$ds}readme", $files[0]->getRelativePathname());
Expand Down

0 comments on commit 8d80a2d

Please sign in to comment.