Skip to content

Commit dd0f29c

Browse files
ro0NLnicolas-grekas
authored andcommitted
[DI] Deprecated using env vars with cannotBeEmpty()
1 parent 3c8c8f7 commit dd0f29c

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
@@ -210,6 +210,38 @@ public function testEmptyEnvWhichCannotBeEmptyForScalarNode(): void
210210
$this->assertSame($expected, $container->resolveEnvPlaceholders($ext->getConfig()));
211211
}
212212

213+
/**
214+
* NOT LEGACY (test exception in 5.0).
215+
*
216+
* @group legacy
217+
* @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.
218+
*/
219+
public function testEmptyEnvWhichCannotBeEmptyForScalarNodeWithValidation(): void
220+
{
221+
$container = new ContainerBuilder();
222+
$container->registerExtension($ext = new EnvExtension());
223+
$container->prependExtensionConfig('env_extension', $expected = array(
224+
'scalar_node_not_empty_validated' => '%env(SOME)%',
225+
));
226+
227+
$this->doProcess($container);
228+
229+
$this->assertSame($expected, $container->resolveEnvPlaceholders($ext->getConfig()));
230+
}
231+
232+
public function testPartialEnvWhichCannotBeEmptyForScalarNode(): void
233+
{
234+
$container = new ContainerBuilder();
235+
$container->registerExtension($ext = new EnvExtension());
236+
$container->prependExtensionConfig('env_extension', $expected = array(
237+
'scalar_node_not_empty_validated' => 'foo %env(SOME)% bar',
238+
));
239+
240+
$this->doProcess($container);
241+
242+
$this->assertSame($expected, $container->resolveEnvPlaceholders($ext->getConfig()));
243+
}
244+
213245
public function testEnvWithVariableNode(): void
214246
{
215247
$container = new ContainerBuilder();
@@ -281,6 +313,14 @@ public function getConfigTreeBuilder()
281313
->children()
282314
->scalarNode('scalar_node')->end()
283315
->scalarNode('scalar_node_not_empty')->cannotBeEmpty()->end()
316+
->scalarNode('scalar_node_not_empty_validated')
317+
->cannotBeEmpty()
318+
->validate()
319+
->always(function ($value) {
320+
return $value;
321+
})
322+
->end()
323+
->end()
284324
->integerNode('int_node')->end()
285325
->floatNode('float_node')->end()
286326
->booleanNode('bool_node')->end()

0 commit comments

Comments
 (0)