@@ -210,6 +210,38 @@ public function testEmptyEnvWhichCannotBeEmptyForScalarNode(): void
210
210
$ this ->assertSame ($ expected , $ container ->resolveEnvPlaceholders ($ ext ->getConfig ()));
211
211
}
212
212
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
+
213
245
public function testEnvWithVariableNode (): void
214
246
{
215
247
$ container = new ContainerBuilder ();
@@ -281,6 +313,14 @@ public function getConfigTreeBuilder()
281
313
->children ()
282
314
->scalarNode ('scalar_node ' )->end ()
283
315
->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 ()
284
324
->integerNode ('int_node ' )->end ()
285
325
->floatNode ('float_node ' )->end ()
286
326
->booleanNode ('bool_node ' )->end ()
0 commit comments