diff --git a/src/Symfony/Component/Finder/Finder.php b/src/Symfony/Component/Finder/Finder.php index 4cf723bf33..82c2ec78dc 100644 --- a/src/Symfony/Component/Finder/Finder.php +++ b/src/Symfony/Component/Finder/Finder.php @@ -669,7 +669,8 @@ class Finder implements \IteratorAggregate, \Countable } elseif ($iterator instanceof \Traversable || \is_array($iterator)) { $it = new \ArrayIterator(); foreach ($iterator as $file) { - $it->append($file instanceof \SplFileInfo ? $file : new \SplFileInfo($file)); + $file = $file instanceof \SplFileInfo ? $file : new \SplFileInfo($file); + $it[$file->getPathname()] = $file; } $this->iterators[] = $it; } else { diff --git a/src/Symfony/Component/Finder/Tests/FinderTest.php b/src/Symfony/Component/Finder/Tests/FinderTest.php index db3c4a55ef..dbc66cbc47 100644 --- a/src/Symfony/Component/Finder/Tests/FinderTest.php +++ b/src/Symfony/Component/Finder/Tests/FinderTest.php @@ -1119,6 +1119,17 @@ class FinderTest extends Iterator\RealIteratorTestCase $this->assertIterator(iterator_to_array($finder->getIterator()), $finder1->getIterator()); } + public function testMultipleAppendCallsWithSorting() + { + $finder = $this->buildFinder() + ->sortByName() + ->append([self::$tmpDir.\DIRECTORY_SEPARATOR.'qux_1000_1.php']) + ->append([self::$tmpDir.\DIRECTORY_SEPARATOR.'qux_1002_0.php']) + ; + + $this->assertOrderedIterator($this->toAbsolute(['qux_1000_1.php', 'qux_1002_0.php']), $finder->getIterator()); + } + public function testCountDirectories() { $directory = Finder::create()->directories()->in(self::$tmpDir);