Repository: symfony/symfony
File: src/Symfony/Component/Finder/Tests/FinderTest.php (PHP)

Code before:

        $this->assertSame(
            [
                // $finder1's ->in()
                self::$tmpDir . '/foo/bar.tmp' => 'bar.tmp',
                // $finder2's ->in()
                self::$tmpDir . '/qux' => 'qux',
                // new \SplFileInfo('toto')
                self::$tmpDir . '/toto' => self::$tmpDir . '/toto',
                // 'foo'
                self::$tmpDir . '/foo' => self::$tmpDir . '/foo',
            ],
            array_map(
                fn (SplFileInfo $item) => $item->getRelativePathname(),
                iterator_to_array($finder1),
            ),
        );

        $finder3 = $this->buildFinder();
        $finder3->append($this->toAbsolute(['foo']));
        $this->assertSame(
            [
                self::$tmpDir . '/foo' =>  self::$tmpDir . '/foo'
            ],
            array_map(
                fn (SplFileInfo $item) => $item->getRelativePathname(),
                iterator_to_array($finder3),
            ),
        );
    }

    public function testAppendReturnsAFinder()
    {
        $this->assertInstanceOf(Finder::class, Finder::create()->append([]));
    }

    public function testAppendDoesNotRequireIn()
    {
        $finder = $this->buildFinder();
        $finder->in(self::$tmpDir.\DIRECTORY_SEPARATOR.'foo');

        $finder1 = Finder::create()->append($finder);

        $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'])

Review comment (suggestion):
```suggestion
                self::$tmpDir.'/foo' =>  self::$tmpDir.'/foo'
            ],
            array_map(
                static fn ($item) => $item->getRelativePathname(),
```

Code after:
                        'c2' => '',
                    ],
                ],
            ],
        ]);

        $formatForAssert = static function (Finder $finder) {
            $data = [];
            foreach ($finder as $key => $value) {
                $data[] = ['key' => $key, 'relativePathname' => $value->getRelativePathname()];
            }

            return $data;
        };

        $dir = $this->vfsScheme.'://';

        // no append
        $finder = Finder::create()->sortByName()->in($dir.'a/b');
        $this->assertSame(
            [
                ['key' => $dir.'a/b/b1', 'relativePathname' => 'b1'],
                ['key' => $dir.'a/b/b2', 'relativePathname' => 'b2'],
                ['key' => $dir.'a/b/c', 'relativePathname' => 'c'],
                ['key' => $dir.'a/b/c/c1', 'relativePathname' => 'c/c1'],
                ['key' => $dir.'a/b/c/c2', 'relativePathname' => 'c/c2'],
            ],
            $formatForAssert($finder),
        );

        // appending another Finder with parent directory
        $finder = Finder::create()->sortByName()->in($dir.'a/b');
        $finder->append(Finder::create()->sortByName()->in($dir.'a'));
        $this->assertSame(
            [
                ['key' => $dir.'a/a1', 'relativePathname' => 'a1'],
                ['key' => $dir.'a/a2', 'relativePathname' => 'a2'],
                ['key' => $dir.'a/b', 'relativePathname' => 'b'],
                ['key' => $dir.'a/b/b1', 'relativePathname' => 'b/b1'],
                ['key' => $dir.'a/b/b2', 'relativePathname' => 'b/b2'],
                ['key' => $dir.'a/b/c', 'relativePathname' => 'b/c'],
                ['key' => $dir.'a/b/c/c1', 'relativePathname' => 'b/c/c1'],
                ['key' => $dir.'a/b/c/c2', 'relativePathname' => 'b/c/c2'],
            ],
            $formatForAssert($finder),
        );

        // appending another Finder with child directory
        $finder = Finder::create()->sortByName()->in($dir.'a/b');
        $finder->append(Finder::create()->sortByName()->in($dir.'a/b/c'));
        $this->assertSame(