8000 [Config] Allow using environment variables in `EnumNode` by ecourtial · Pull Request #45624 · symfony/symfony · GitHub
[go: up one dir, main page]

Skip to content

[Config] Allow using environment variables in EnumNode #45624

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Mar 9, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions src/Symfony/Component/Config/CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,11 @@
CHANGELOG
=========

6.1
---

* Allow using environment variables in `EnumNode`

6.0
---

Expand Down
8 changes: 0 additions & 8 deletions src/Symfony/Component/Config/Definition/EnumNode.php
Original file line number Diff line number Diff line change
Expand Up @@ -54,12 +54,4 @@ protected function finalizeValue(mixed $value): mixed

return $value;
}

/**
* {@inheritdoc}
*/
protected function allowPlaceholders(): bool
{
return false;
}
}
16 changes: 16 additions & 0 deletions src/Symfony/Component/Config/Tests/Definition/EnumNodeTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -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');
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down
0