Skip to content

Commit a2f2769

Browse files
minor #31678 [Config] Removed env var support with cannotBeEmpty() (ro0NL)
This PR was merged into the 5.0-dev branch. Discussion ---------- [Config] Removed env var support with cannotBeEmpty() | Q | A | ------------- | --- | Branch? | master | Bug fix? | no | New feature? | no | BC breaks? | no <!-- see https://symfony.com/bc --> | Deprecations? | no | Tests pass? | yes <!-- please add some, will be required by reviewers --> | Fixed tickets | #... <!-- #-prefixed issue number(s), if any --> | License | MIT | Doc PR | symfony/symfony-docs#... <!-- required for new features --> See #28858 Commits ------- ec27d74 [Config] Removed env var support with cannotBeEmpty()
2 parents 8e84328 + ec27d74 commit a2f2769

File tree

2 files changed

+14
-14
lines changed

2 files changed

+14
-14
lines changed

src/Symfony/Component/Config/Definition/VariableNode.php

Lines changed: 7 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -84,14 +84,13 @@ protected function finalizeValue($value)
8484
// deny environment variables only when using custom validators
8585
// this avoids ever passing an empty value to final validation closures
8686
if (!$this->allowEmptyValue && $this->isHandlingPlaceholder() && $this->finalValidationClosures) {
87-
@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);
88-
// $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)));
89-
// if ($hint = $this->getInfo()) {
90-
// $e->addHint($hint);
91-
// }
92-
// $e->setPath($this->getPath());
93-
//
94-
// throw $e;
87+
$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)));
88+
if ($hint = $this->getInfo()) {
89+
$e->addHint($hint);
90+
}
91+
$e->setPath($this->getPath());
92+
93+
throw $e;
9594
}
9695

9796
if (!$this->allowEmptyValue && $this->isValueEmpty($value)) {

src/Symfony/Component/DependencyInjection/Tests/Compiler/ValidateEnvPlaceholdersPassTest.php

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@
1212
namespace Symfony\Component\DependencyInjection\Tests\Compiler;
1313

1414
use PHPUnit\Framework\TestCase;
15+
use Symfony\Component\Config\Definition\Builder\ParentNodeDefinitionInterface;
1516
use Symfony\Component\Config\Definition\Builder\TreeBuilder;
1617
use Symfony\Component\Config\Definition\ConfigurationInterface;
1718
use Symfony\Component\DependencyInjection\Compiler\MergeExtensionConfigurationPass;
@@ -229,22 +230,22 @@ public function testEmptyEnvWhichCannotBeEmptyForScalarNode(): void
229230
}
230231

231232
/**
232-
* NOT LEGACY (test exception in 5.0).
233-
*
234-
* @group legacy
235-
* @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.
233+
* @expectedException \Symfony\Component\Config\Definition\Exception\InvalidConfigurationException
234+
* @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.
236235
*/
237236
public function testEmptyEnvWhichCannotBeEmptyForScalarNodeWithValidation(): void
238237
{
238+
if (!method_exists(ParentNodeDefinitionInterface::class, 'getChildNodeDefinitions')) {
239+
$this->markTestSkipped('symfony/config >=5.0 is required.');
240+
}
241+
239242
$container = new ContainerBuilder();
240243
$container->registerExtension($ext = new EnvExtension());
241244
$container->prependExtensionConfig('env_extension', $expected = [
242245
'scalar_node_not_empty_validated' => '%env(SOME)%',
243246
]);
244247

245248
$this->doProcess($container);
246-
247-
$this->assertSame($expected, $container->resolveEnvPlaceholders($ext->getConfig()));
248249
}
249250

250251
public function testPartialEnvWhichCannotBeEmptyForScalarNode(): void

0 commit comments

Comments
 (0)