Skip to content

Commit 864c47f

Browse files
feature #28858 [DI] Deprecated using env vars with cannotBeEmpty() (ro0NL)
This PR was squashed before being merged into the 4.3-dev branch (closes #28858). Discussion ---------- [DI] Deprecated using env vars with cannotBeEmpty() | Q | A | ------------- | --- | Branch? | master | Bug fix? | yes-ish | New feature? | yes | BC breaks? | no <!-- see https://symfony.com/bc --> | Deprecations? | yes | Tests pass? | yes <!-- please add some, will be required by reviewers --> | Fixed tickets | #28827 | License | MIT | Doc PR | symfony/symfony-docs#... <!-- required for new features --> Continuation of #28838 for 4.2 Using environment variables for nodes marked `cannotBeEmpty()` is semantically not possible, we'll never know the value is empty yes/no during compile time. Neither we should assume one or another. Commits ------- 397c19ee5f [DI] Deprecated using env vars with cannotBeEmpty()
2 parents e2c2627 + dd0f29c commit 864c47f

File tree

1 file changed

+40
-0
lines changed

1 file changed

+40
-0
lines changed

Tests/Compiler/ValidateEnvPlaceholdersPassTest.php

Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -211,6 +211,38 @@ public function testEmptyEnvWhichCannotBeEmptyForScalarNode(): void
211211
$this->assertSame($expected, $container->resolveEnvPlaceholders($ext->getConfig()));
212212
}
213213

214+
/**
215+
* NOT LEGACY (test exception in 5.0).
216+
*
217+
* @group legacy
218+
* @expectedDeprecation Setting path "env_extension.scalar_node_not_empty_validated" to an environment variable is deprecated since Symfony 4.2. Remove "cannotBeEmpty()", "validate()" or include a prefix/suffix value instead.
219+
*/
220+
public function testEmptyEnvWhichCannotBeEmptyForScalarNodeWithValidation(): void
221+
{
222+
$container = new ContainerBuilder();
223+
$container->registerExtension($ext = new EnvExtension());
224+
$container->prependExtensionConfig('env_extension', $expected = array(
225+
'scalar_node_not_empty_validated' => '%env(SOME)%',
226+
));
227+
228+
$this->doProcess($container);
229+
230+
$this->assertSame($expected, $container->resolveEnvPlaceholders($ext->getConfig()));
231+
}
232+
233+
public function testPartialEnvWhichCannotBeEmptyForScalarNode(): void
234+
{
235+
$container = new ContainerBuilder();
236+
$container->registerExtension($ext = new EnvExtension());
237+
$container->prependExtensionConfig('env_extension', $expected = array(
238+
'scalar_node_not_empty_validated' => 'foo %env(SOME)% bar',
239+
));
240+
241+
$this->doProcess($container);
242+
243+
$this->assertSame($expected, $container->resolveEnvPlaceholders($ext->getConfig()));
244+
}
245+
214246
public function testEnvWithVariableNode(): void
215247
{
216248
$container = new ContainerBuilder();
@@ -282,6 +314,14 @@ public function getConfigTreeBuilder()
282314
->children()
283315
->scalarNode('scalar_node')->end()
284316
->scalarNode('scalar_node_not_empty')->cannotBeEmpty()->end()
317+
->scalarNode('scalar_node_not_empty_validated')
318+
->cannotBeEmpty()
319+
->validate()
320+
->always(function ($value) {
321+
return $value;
322+
})
323+
->end()
324+
->end()
285325
->integerNode('int_node')->end()
286326
->floatNode('float_node')->end()
287327
->booleanNode('bool_node')->end()

0 commit comments

Comments
 (0)