[DI][Config] Fix empty env validation

This commit is contained in:
Roland Franssen 2018-04-04 18:31:13 +02:00
parent e973f6f380
commit d40a4f409d
3 changed files with 26 additions and 0 deletions

View File

@ -476,6 +476,14 @@ abstract class BaseNode implements NodeInterface
return true;
}
/**
* Tests if a placeholder is being handled currently.
*/
protected function isHandlingPlaceholder(): bool
{
return null !== $this->handlingPlaceholder;
}
/**
* Gets allowed dynamic types for this node.
*/

View File

@ -52,6 +52,10 @@ class ScalarNode extends VariableNode
*/
protected function isValueEmpty($value)
{
if ($this->isHandlingPlaceholder()) {
return false;
}
return null === $value || '' === $value;
}

View File

@ -196,6 +196,19 @@ class ValidateEnvPlaceholdersPassTest extends TestCase
$this->assertSame($expected, $container->resolveEnvPlaceholders($ext->getConfig()));
}
public function testEmptyEnvWithCannotBeEmptyForScalarNode(): void
{
$container = new ContainerBuilder();
$container->registerExtension($ext = new EnvExtension());
$container->prependExtensionConfig('env_extension', $expected = array(
'scalar_node_not_empty' => '%env(SOME)%',
));
$this->doProcess($container);
$this->assertSame($expected, $container->resolveEnvPlaceholders($ext->getConfig()));
}
private function doProcess(ContainerBuilder $container): void
{
(new MergeExtensionConfigurationPass())->process($container);
@ -213,6 +226,7 @@ class EnvConfiguration implements ConfigurationInterface
$rootNode
->children()
->scalarNode('scalar_node')->end()
->scalarNode('scalar_node_not_empty')->cannotBeEmpty()->end()
->integerNode('int_node')->end()
->floatNode('float_node')->end()
->booleanNode('bool_node')->end()