Repository: symfony/symfony
File: src/Symfony/Component/DependencyInjection/Tests/Loader/PhpFileLoaderTest.php (PHP)

Code before:
    {
        $loader = new PhpFileLoader(new ContainerBuilder(), new FileLocator());

        $this->assertTrue($loader->supports('foo.php'), '->supports() returns true if the resource is loadable');
        $this->assertFalse($loader->supports('foo.foo'), '->supports() returns false if the resource is not loadable');
        $this->assertTrue($loader->supports('with_wrong_ext.yml', 'php'), '->supports() returns true if the resource with forced type is loadable');
    }

    public function testLoad()
    {
        $loader = new PhpFileLoader($container = new ContainerBuilder(), new FileLocator());

        $loader->load(__DIR__.'/../Fixtures/php/simple.php');

        $this->assertEquals('foo', $container->getParameter('foo'), '->load() loads a PHP file resource');

        $this->assertTrue(class_exists(App::class));
        $this->assertTrue(\function_exists('Symfony\Component\DependencyInjection\Loader\Configurator\service'));
    }

    public function testPrependExtensionConfigWithLoadMethod()
    {
        $container = new ContainerBuilder();
        $container->registerExtension(new \AcmeExtension());
        $container->prependExtensionConfig('acme', ['foo' => 'bar']);
        $loader = new PhpFileLoader($container, new FileLocator(\dirname(__DIR__).'/Fixtures/config'), 'prod', new ConfigBuilderGenerator(sys_get_temp_dir()), true);
        $loader->load('config_builder.php');

        $expected = [
            ['color' => 'red'],
            ['color' => 'blue'],
            ['foo' => 'bar'],
        ];
        $this->assertSame($expected, $container->getExtensionConfig('acme'));
    }

    public function testPrependExtensionConfigWithImportMethod()
    {
        $container = new ContainerBuilder();
        $container->registerExtension(new \AcmeExtension());
        $container->prependExtensionConfig('acme', ['foo' => 'bar']);
        $loader = new PhpFileLoader($container, new FileLocator(\dirname(__DIR__).'/Fixtures/config'), 'prod', new ConfigBuilderGenerator(sys_get_temp_dir()), true);
        $loader->import('config_builder.php');

        $expected = [
            ['color' => 'red'],
            ['color' => 'blue'],
            ['foo' => 'bar'],
        ];
        $this->assertSame($expected, $container->getExtensionConfig('acme'));
    }

Review comment (suggestion):
Tests should not use named parameters. This hides unintentional BC breaks that would be detected due to tests being forced to be updated, by making tests used the public API.

Code after:
    {
        $loader = new PhpFileLoader(new ContainerBuilder(), new FileLocator());

        $this->assertTrue($loader->supports('foo.php'), '->supports() returns true if the resource is loadable');
        $this->assertFalse($loader->supports('foo.foo'), '->supports() returns false if the resource is not loadable');
        $this->assertTrue($loader->supports('with_wrong_ext.yml', 'php'), '->supports() returns true if the resource with forced type is loadable');
    }

    public function testLoad()
    {
        $loader = new PhpFileLoader($container = new ContainerBuilder(), new FileLocator());

        $loader->load(__DIR__.'/../Fixtures/php/simple.php');

        $this->assertEquals('foo', $container->getParameter('foo'), '->load() loads a PHP file resource');

        $this->assertTrue(class_exists(App::class));
        $this->assertTrue(\function_exists('Symfony\Component\DependencyInjection\Loader\Configurator\service'));
    }

    public function testPrependExtensionConfigWithLoadMethod()
    {
        $container = new ContainerBuilder();
        $container->registerExtension(new \AcmeExtension());
        $container->prependExtensionConfig('acme', ['foo' => 'bar']);
        $loader = new PhpFileLoader($container, new FileLocator(\dirname(__DIR__).'/Fixtures/config'), 'prod', prepend: true);
        $loader->load('config_builder.php');

        $expected = [
            ['color' => 'red'],
            ['color' => 'blue'],
            ['foo' => 'bar'],
        ];
        $this->assertSame($expected, $container->getExtensionConfig('acme'));
    }

    public function testPrependExtensionConfigWithImportMethod()
    {
        $container = new ContainerBuilder();
        $container->registerExtension(new \AcmeExtension());
        $container->prependExtensionConfig('acme', ['foo' => 'bar']);
        $loader = new PhpFileLoader($container, new FileLocator(\dirname(__DIR__).'/Fixtures/config'), 'prod', prepend: true);
        $loader->import('config_builder.php');

        $expected = [
            ['color' => 'red'],
            ['color' => 'blue'],
            ['foo' => 'bar'],
        ];
        $this->assertSame($expected, $container->getExtensionConfig('acme'));
    }