diff --git a/src/Symfony/Component/Config/Definition/VariableNode.php b/src/Symfony/Component/Config/Definition/VariableNode.php index 0d722c6bd2..0bcb28f233 100644 --- a/src/Symfony/Component/Config/Definition/VariableNode.php +++ b/src/Symfony/Component/Config/Definition/VariableNode.php @@ -84,14 +84,13 @@ class VariableNode extends BaseNode implements PrototypeNodeInterface // deny environment variables only when using custom validators // this avoids ever passing an empty value to final validation closures if (!$this->allowEmptyValue && $this->isHandlingPlaceholder() && $this->finalValidationClosures) { - @trigger_error(sprintf('Setting path "%s" to an environment variable is deprecated since Symfony 4.3. Remove "cannotBeEmpty()", "validate()" or include a prefix/suffix value instead.', $this->getPath()), E_USER_DEPRECATED); -// $e = new InvalidConfigurationException(sprintf('The path "%s" cannot contain an environment variable when empty values are not allowed by definition and are validated.', $this->getPath(), json_encode($value))); -// if ($hint = $this->getInfo()) { -// $e->addHint($hint); -// } -// $e->setPath($this->getPath()); -// -// throw $e; + $e = new InvalidConfigurationException(sprintf('The path "%s" cannot contain an environment variable when empty values are not allowed by definition and are validated.', $this->getPath(), json_encode($value))); + if ($hint = $this->getInfo()) { + $e->addHint($hint); + } + $e->setPath($this->getPath()); + + throw $e; } if (!$this->allowEmptyValue && $this->isValueEmpty($value)) { diff --git a/src/Symfony/Component/DependencyInjection/Tests/Compiler/ValidateEnvPlaceholdersPassTest.php b/src/Symfony/Component/DependencyInjection/Tests/Compiler/ValidateEnvPlaceholdersPassTest.php index 84d6d8db82..bfc4b2c56e 100644 --- a/src/Symfony/Component/DependencyInjection/Tests/Compiler/ValidateEnvPlaceholdersPassTest.php +++ b/src/Symfony/Component/DependencyInjection/Tests/Compiler/ValidateEnvPlaceholdersPassTest.php @@ -12,6 +12,7 @@ namespace Symfony\Component\DependencyInjection\Tests\Compiler; use PHPUnit\Framework\TestCase; +use Symfony\Component\Config\Definition\Builder\ParentNodeDefinitionInterface; use Symfony\Component\Config\Definition\Builder\TreeBuilder; use Symfony\Component\Config\Definition\ConfigurationInterface; use Symfony\Component\DependencyInjection\Compiler\MergeExtensionConfigurationPass; @@ -229,13 +230,15 @@ class ValidateEnvPlaceholdersPassTest extends TestCase } /** - * NOT LEGACY (test exception in 5.0). - * - * @group legacy - * @expectedDeprecation Setting path "env_extension.scalar_node_not_empty_validated" to an environment variable is deprecated since Symfony 4.3. Remove "cannotBeEmpty()", "validate()" or include a prefix/suffix value instead. + * @expectedException \Symfony\Component\Config\Definition\Exception\InvalidConfigurationException + * @expectedExceptionMessage The path "env_extension.scalar_node_not_empty_validated" cannot contain an environment variable when empty values are not allowed by definition and are validated. */ public function testEmptyEnvWhichCannotBeEmptyForScalarNodeWithValidation(): void { + if (!method_exists(ParentNodeDefinitionInterface::class, 'getChildNodeDefinitions')) { + $this->markTestSkipped('symfony/config >=5.0 is required.'); + } + $container = new ContainerBuilder(); $container->registerExtension($ext = new EnvExtension()); $container->prependExtensionConfig('env_extension', $expected = [ @@ -243,8 +246,6 @@ class ValidateEnvPlaceholdersPassTest extends TestCase ]); $this->doProcess($container); - - $this->assertSame($expected, $container->resolveEnvPlaceholders($ext->getConfig())); } public function testPartialEnvWhichCannotBeEmptyForScalarNode(): void