Repository: symfony/symfony
File: src/Symfony/Bundle/FrameworkBundle/Tests/DependencyInjection/Compiler/PhpConfigReferenceDumpPassTest.php (PHP)

Code before:
        $this->assertStringContainsString('namespace Symfony\Component\DependencyInjection\Loader\Configurator;', $content);
        $this->assertStringContainsString('final class App extends AppReference', $content);
        $this->assertStringContainsString('public static function config(array $config): array', $content);
        $this->assertEquals([new FileResource(realpath($this->tempDir).'/reference.php')], $container->getResources());
    }

    public function testProcessIgnoresFileWriteErrors()
    {
        if ('\\' === \DIRECTORY_SEPARATOR) {
            self::markTestSkipped('Cannot reliably make directory read-only on Windows.');
        }

        // Create a read-only directory to simulate write errors
        $readOnlyDir = $this->tempDir.'/readonly';
        mkdir($readOnlyDir, 0o444, true);

        $container = new ContainerBuilder();
        $container->setParameter('.container.known_envs', ['dev', 'prod', 'test']);

        $pass = new PhpConfigReferenceDumpPass($readOnlyDir.'/reference.php', [
            TestBundle::class => ['all' => true],
        ]);

        $pass->process($container);
        $this->assertFileDoesNotExist($readOnlyDir.'/reference.php');
        $this->assertEquals([], $container->getResources());
    }

    public function testProcessGeneratesExpectedReferenceFile()
    {
        $container = new ContainerBuilder();
        $container->setParameter('.container.known_envs', ['dev', 'prod', 'test']);

        $extension = new TestExtension();
        $container->registerExtension($extension);

        $pass = new PhpConfigReferenceDumpPass($this->tempDir.'/reference.php', [
            TestBundle::class => ['all' => true],
        ]);
        $pass->process($container);

        if ($_ENV['TEST_GENERATE_FIXTURES'] ?? false) {
            copy($this->tempDir.'/reference.php', __DIR__.'/../../Fixtures/reference.php');
            self::markTestIncomplete('TEST_GENERATE_FIXTURES is set');
        }

        $this->assertFileEquals(__DIR__.'/../../Fixtures/reference.php', $this->tempDir.'/reference.php');
        $this->assertEquals([new FileResource(realpath($this->tempDir).'/reference.php')], $container->getResources());
    }
}


Review comment (suggestion):
```suggestion
        $this->assertSame([], $container->getResources());
```

Code after:
        $content = file_get_contents($referenceFile);
        $this->assertStringContainsString('namespace Symfony\Component\DependencyInjection\Loader\Configurator;', $content);
        $this->assertStringContainsString('final class App extends AppReference', $content);
        $this->assertStringContainsString('public static function config(array $config): array', $content);
        $this->assertEquals([new FileResource(realpath($this->tempDir).'/reference.php')], $container->getResources());
    }

    public function testProcessIgnoresFileWriteErrors()
    {
        if ('\\' === \DIRECTORY_SEPARATOR) {
            self::markTestSkipped('Cannot reliably make directory read-only on Windows.');
        }

        // Create a read-only directory to simulate write errors
        $readOnlyDir = $this->tempDir.'/readonly';
        mkdir($readOnlyDir, 0o444, true);

        $container = new ContainerBuilder();
        $container->setParameter('.container.known_envs', ['dev', 'prod', 'test']);

        $pass = new PhpConfigReferenceDumpPass($readOnlyDir.'/reference.php', [
            TestBundle::class => ['all' => true],
        ]);

        $pass->process($container);
        $this->assertFileDoesNotExist($readOnlyDir.'/reference.php');
        $this->assertEmpty($container->getResources());
    }

    public function testProcessGeneratesExpectedReferenceFile()
    {
        $container = new ContainerBuilder();
        $container->setParameter('.container.known_envs', ['dev', 'prod', 'test']);

        $extension = new TestExtension();
        $container->registerExtension($extension);

        $pass = new PhpConfigReferenceDumpPass($this->tempDir.'/reference.php', [
            TestBundle::class => ['all' => true],
        ]);
        $pass->process($container);

        if ($_ENV['TEST_GENERATE_FIXTURES'] ?? false) {
            copy($this->tempDir.'/reference.php', __DIR__.'/../../Fixtures/reference.php');
            self::markTestIncomplete('TEST_GENERATE_FIXTURES is set');
        }

        $this->assertFileEquals(__DIR__.'/../../Fixtures/reference.php', $this->tempDir.'/reference.php');
        $this->assertEquals([new FileResource(realpath($this->tempDir).'/reference.php')], $container->getResources());
    }