From 726bc280e82c87fb5382d54caf73ddccfa9b0b1f Mon Sep 17 00:00:00 2001 From: Eric COURTIAL Date: Thu, 3 Mar 2022 12:56:41 +0100 Subject: [PATCH] [Config] Allow using environment variables in `EnumNode` --- src/Symfony/Component/Config/CHANGELOG.md | 5 +++++ .../Component/Config/Definition/EnumNode.php | 8 -------- .../Config/Tests/Definition/EnumNodeTest.php | 16 ++++++++++++++++ .../Compiler/ValidateEnvPlaceholdersPassTest.php | 13 ------------- 4 files changed, 21 insertions(+), 21 deletions(-) diff --git a/src/Symfony/Component/Config/CHANGELOG.md b/src/Symfony/Component/Config/CHANGELOG.md index bc34ee5aeb997..ece499acdfb34 100644 --- a/src/Symfony/Component/Config/CHANGELOG.md +++ b/src/Symfony/Component/Config/CHANGELOG.md @@ -1,6 +1,11 @@ CHANGELOG ========= +6.1 +--- + + * Allow using environment variables in `EnumNode` + 6.0 --- diff --git a/src/Symfony/Component/Config/Definition/EnumNode.php b/src/Symfony/Component/Config/Definition/EnumNode.php index 0001dd4946d3e..3a777119171f7 100644 --- a/src/Symfony/Component/Config/Definition/EnumNode.php +++ b/src/Symfony/Component/Config/Definition/EnumNode.php @@ -54,12 +54,4 @@ protected function finalizeValue(mixed $value): mixed return $value; } - - /** - * {@inheritdoc} - */ - protected function allowPlaceholders(): bool - { - return false; - } } diff --git a/src/Symfony/Component/Config/Tests/Definition/EnumNodeTest.php b/src/Symfony/Component/Config/Tests/Definition/EnumNodeTest.php index 089e74ec3f9a7..b728dec5b1c78 100644 --- a/src/Symfony/Component/Config/Tests/Definition/EnumNodeTest.php +++ b/src/Symfony/Component/Config/Tests/Definition/EnumNodeTest.php @@ -55,4 +55,20 @@ public function testFinalizeWithInvalidValue() $node = new EnumNode('foo', null, ['foo', 'bar']); $node->finalize('foobar'); } + + public function testWithPlaceHolderWithValidValue() + { + $node = new EnumNode('cookie_samesite', null, ['lax', 'strict', 'none']); + EnumNode::setPlaceholder('custom', ['string' => 'lax']); + $this->assertSame('custom', $node->finalize('custom')); + } + + public function testWithPlaceHolderWithInvalidValue() + { + $node = new EnumNode('cookie_samesite', null, ['lax', 'strict', 'none']); + EnumNode::setPlaceholder('custom', ['string' => 'foo']); + $this->expectException(InvalidConfigurationException::class); + $this->expectExceptionMessage('The value "foo" is not allowed for path "cookie_samesite". Permissible values: "lax", "strict", "none"'); + $node->finalize('custom'); + } } diff --git a/src/Symfony/Component/DependencyInjection/Tests/Compiler/ValidateEnvPlaceholdersPassTest.php b/src/Symfony/Component/DependencyInjection/Tests/Compiler/ValidateEnvPlaceholdersPassTest.php index 9d94628f33440..50828a47b4bb3 100644 --- a/src/Symfony/Component/DependencyInjection/Tests/Compiler/ValidateEnvPlaceholdersPassTest.php +++ b/src/Symfony/Component/DependencyInjection/Tests/Compiler/ValidateEnvPlaceholdersPassTest.php @@ -153,19 +153,6 @@ public function testConcatenatedEnvInConfig() $this->assertSame(['scalar_node' => $expected], $container->resolveEnvPlaceholders($ext->getConfig())); } - public function testEnvIsIncompatibleWithEnumNode() - { - $this->expectException(InvalidConfigurationException::class); - $this->expectExceptionMessage('A dynamic value is not compatible with a "Symfony\Component\Config\Definition\EnumNode" node type at path "env_extension.enum_node".'); - $container = new ContainerBuilder(); - $container->registerExtension(new EnvExtension()); - $container->prependExtensionConfig('env_extension', [ - 'enum_node' => '%env(FOO)%', - ]); - - $this->doProcess($container); - } - public function testEnvIsIncompatibleWithArrayNode() { $this->expectException(InvalidConfigurationException::class);