Repository: symfony/symfony
File: src/Symfony/Component/DependencyInjection/Tests/ParameterBag/EnvPlaceholderParameterBagTest.php (PHP)

Code before:
        $this->expectException(RuntimeException::class);
        $this->expectExceptionMessage('The default value of env parameter "ARRAY_VAR" must be a string or null, "array" given.');
        $bag = new EnvPlaceholderParameterBag();
        $bag->get('env(ARRAY_VAR)');
        $bag->set('env(ARRAY_VAR)', []);
        $bag->resolve();
    }

    public function testGetEnvAllowsNull()
    {
        $bag = new EnvPlaceholderParameterBag();
        $bag->set('env(NULL_VAR)', null);
        $bag->get('env(NULL_VAR)');
        $bag->resolve();

        $this->assertNull($bag->all()['env(NULL_VAR)']);
    }

    public function testGetEnvAllowsDot()
    {
        $bag = new EnvPlaceholderParameterBag();
        $bag->set('env(dynamic.var)', 'foo');
        $bag->get('env(dynamic.var)');
        $bag->resolve();

        $this->assertEquals('foo', $bag->all()['env(dynamic.var)']);
    }

    public function testGetThrowsOnBadDefaultValue()
    {
        $this->expectException(RuntimeException::class);
        $this->expectExceptionMessage('The default value of an env() parameter must be a string or null, but "array" given to "env(ARRAY_VAR)".');
        $bag = new EnvPlaceholderParameterBag();
        $bag->set('env(ARRAY_VAR)', []);
        $bag->get('env(ARRAY_VAR)');
        $bag->resolve();
    }

    public function testDefaultToNullAllowed()
    {
        $bag = new EnvPlaceholderParameterBag();
        $bag->resolve();
        $this->assertNotNull($bag->get('env(default::BAR)'));
    }

    public function testExtraCharsInProcessor()
    {
        $bag = new EnvPlaceholderParameterBag();
        $bag->resolve();
        $this->assertStringMatchesFormat('env_%s_key_a_b_c_FOO_%s', $bag->get('env(key:a.b-c:FOO)'));
    }

Review comment (suggestion):
```suggestion
        $this->assertSame('foo', $bag->all()['env(dynamic.var)']);
```

Code after:
        $this->expectException(RuntimeException::class);
        $this->expectExceptionMessage('The default value of env parameter "ARRAY_VAR" must be a string or null, "array" given.');
        $bag = new EnvPlaceholderParameterBag();
        $bag->get('env(ARRAY_VAR)');
        $bag->set('env(ARRAY_VAR)', []);
        $bag->resolve();
    }

    public function testGetEnvAllowsNull()
    {
        $bag = new EnvPlaceholderParameterBag();
        $bag->set('env(NULL_VAR)', null);
        $bag->get('env(NULL_VAR)');
        $bag->resolve();

        $this->assertNull($bag->all()['env(NULL_VAR)']);
    }

    public function testGetEnvAllowsDot()
    {
        $bag = new EnvPlaceholderParameterBag();
        $bag->set('env(dynamic.var)', 'foo');
        $bag->get('env(dynamic.var)');
        $bag->resolve();

        $this->assertSame('foo', $bag->all()['env(dynamic.var)']);
    }

    public function testGetThrowsOnBadDefaultValue()
    {
        $this->expectException(RuntimeException::class);
        $this->expectExceptionMessage('The default value of an env() parameter must be a string or null, but "array" given to "env(ARRAY_VAR)".');
        $bag = new EnvPlaceholderParameterBag();
        $bag->set('env(ARRAY_VAR)', []);
        $bag->get('env(ARRAY_VAR)');
        $bag->resolve();
    }

    public function testDefaultToNullAllowed()
    {
        $bag = new EnvPlaceholderParameterBag();
        $bag->resolve();
        $this->assertNotNull($bag->get('env(default::BAR)'));
    }

    public function testExtraCharsInProcessor()
    {
        $bag = new EnvPlaceholderParameterBag();
        $bag->resolve();
        $this->assertStringMatchesFormat('env_%s_key_a_b_c_FOO_%s', $bag->get('env(key:a.b-c:FOO)'));
    }