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

Code before:

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

        $finder2 = $this->buildFinder();
        $finder2->directories()->in(self::$tmpDir);

        $finder1->append($finder2);
        $finder1->append($this->toAbsolute(['foo']));
        $finder1->append(array_map(fn (string $item): \SplFileInfo => new \SplFileInfo($item), $this->toAbsolute(['toto'])));

        $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();

Review comment (suggestion):
```suggestion
                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(
                static fn ($item) => $item->getRelativePathname(),
```

Code after:

    public function testRelativePathOfAppendedItems()
    {
        $this->setupVfsProvider([
            'a' => [
                'a1' => '',
                'a2' => '',
                'b' => [
                    'b1' => '',
                    'b2' => '',
                    'c' => [
                        'c1' => '',
                        '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'],