8000 bug #40023 [Finder]  use proper keys to not override appended files (… · symfony/symfony@e242832 · GitHub
[go: up one dir, main page]

Skip to content

Commit e242832

Browse files
bug #40023 [Finder]  use proper keys to not override appended files (xabbuh)
This PR was merged into the 4.4 branch. Discussion ---------- [Finder]  use proper keys to not override appended files | Q | A | ------------- | --- | Branch? | 4.4 | Bug fix? | yes | New feature? | no | Deprecations? | no | Tickets | Fix #40022 | License | MIT | Doc PR | Commits ------- 036c8d7 use proper keys to not override appended files
2 parents 27fab22 + 036c8d7 commit e242832

File tree

2 files changed

+13
-1
lines changed

2 files changed

+13
-1
lines changed

src/Symfony/Component/Finder/Finder.php

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -669,7 +669,8 @@ public function append($iterator)
669669
} elseif ($iterator instanceof \Traversable || \is_array($iterator)) {
670670
$it = new \ArrayIterator();
671671
foreach ($iterator as $file) {
672-
$it->append($file instanceof \SplFileInfo ? $file : new \SplFileInfo($file));
672+
$file = $file instanceof \SplFileInfo ? $file : new \SplFileInfo($file);
673+
$it[$file->getPathname()] = $file;
673674
}
674675
$this->iterators[] = $it;
675676
} else {

src/Symfony/Component/Finder/Tests/FinderTest.php

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1119,6 +1119,17 @@ public function testAppendDoesNotRequireIn()
11191119
$this->assertIterator(iterator_to_array($finder->getIterator()), $finder1->getIterator());
11201120
}
11211121

1122+
public function testMultipleAppendCallsWithSorting()
1123+
{
1124+
$finder = $this->buildFinder()
1125+
->sortByName()
1126+
->append([self::$tmpDir.\DIRECTORY_SEPARATOR.'qux_1000_1.php'])
1127+
->append([self::$tmpDir.\DIRECTORY_SEPARATOR.'qux_1002_0.php'])
1128+
;
1129+
1130+
$this->assertOrderedIterator($this->toAbsolute(['qux_1000_1.php', 'qux_1002_0.php']), $finder->getIterator());
1131+
}
1132+
11221133
public function testCountDirectories()
11231134
{
11241135
$directory = Finder::create()->directories()->in(self::$tmpDir);

0 commit comments

Comments
 (0)
0