Skip to content

Commit

Permalink
[DependencyInjection] Fix ContainerBuilder stats env usage with enum
Browse files Browse the repository at this point in the history
  • Loading branch information
alamirault authored and nicolas-grekas committed Dec 6, 2022
1 parent 97f0ce8 commit 75da869
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 1 deletion.
Expand Up @@ -49,7 +49,7 @@ public function get(string $name): array|bool|string|int|float|\UnitEnum|null
}

$uniqueName = md5($name.'_'.self::$counter++);
$placeholder = sprintf('%s_%s_%s', $this->getEnvPlaceholderUniquePrefix(), strtr($env, ':-.', '___'), $uniqueName);
$placeholder = sprintf('%s_%s_%s', $this->getEnvPlaceholderUniquePrefix(), strtr($env, ':-.\\', '____'), $uniqueName);
$this->envPlaceholders[$env][$placeholder] = $placeholder;

return $placeholder;
Expand Down
Expand Up @@ -51,6 +51,7 @@
use Symfony\Component\DependencyInjection\Tests\Fixtures\FooWithAbstractArgument;
use Symfony\Component\DependencyInjection\Tests\Fixtures\ScalarFactory;
use Symfony\Component\DependencyInjection\Tests\Fixtures\SimilarArgumentsDummy;
use Symfony\Component\DependencyInjection\Tests\Fixtures\StringBackedEnum;
use Symfony\Component\DependencyInjection\Tests\Fixtures\WitherStaticReturnType;
use Symfony\Component\DependencyInjection\TypedReference;
use Symfony\Component\ExpressionLanguage\Expression;
Expand Down Expand Up @@ -545,6 +546,23 @@ public function testEnvExpressionFunction()
$this->assertEquals('Foo value', $container->get('bar')->foo);
}

public function testGetEnvCountersWithEnum()
{
$bag = new EnvPlaceholderParameterBag();
$config = new ContainerBuilder($bag);
$config->resolveEnvPlaceholders([
$bag->get('env(enum:'.StringBackedEnum::class.':foo)'),
$bag->get('env(Bar)'),
]);

$expected = [
'enum:Symfony\Component\DependencyInjection\Tests\Fixtures\StringBackedEnum:foo' => 1,
'Bar' => 1,
];

$this->assertSame($expected, $config->getEnvCounters());
}

public function testCreateServiceWithAbstractArgument()
{
$this->expectException(RuntimeException::class);
Expand Down

0 comments on commit 75da869

Please sign in to comment.