@@ -226,14 +226,29 @@ public function testEnvWithVariableNode(): void
226
226
public function testConfigurationWithoutRootNode (): void
227
227
{
228
228
$ container = new ContainerBuilder ();
229
- $ container ->registerExtension ($ ext = new EnvExtension (new EnvConfigurationWithoutRootNode ()));
229
+ $ container ->registerExtension (new EnvExtension (new EnvConfigurationWithoutRootNode ()));
230
230
$ container ->loadFromExtension ('env_extension ' );
231
231
232
232
$ this ->doProcess ($ container );
233
233
234
234
$ this ->addToAssertionCount (1 );
235
235
}
236
236
237
+ public function testDiscardedEnvInConfig (): void
238
+ {
239
+ $ container = new ContainerBuilder ();
240
+ $ container ->setParameter ('env(BOOLISH) ' , '1 ' );
241
+ $ container ->setParameter ('boolish ' , '%env(BOOLISH)% ' );
242
+ $ container ->registerExtension (new EnvExtension ());
243
+ $ container ->prependExtensionConfig ('env_extension ' , array (
244
+ 'array_node ' => array ('bool_force_cast ' => '%boolish% ' ),
245
+ ));
246
+
247
+ $ container ->compile (true );
248
+
249
+ $ this ->assertSame ('1 ' , $ container ->getParameter ('boolish ' ));
250
+ }
251
+
237
252
private function doProcess (ContainerBuilder $ container ): void
238
253
{
239
254
(new MergeExtensionConfigurationPass ())->process ($ container );
@@ -260,8 +275,19 @@ public function getConfigTreeBuilder()
260
275
->ifTrue (function ($ value ) { return !is_array ($ value ); })
261
276
->then (function ($ value ) { return array ('child_node ' => $ value ); })
262
277
->end ()
278
+ ->beforeNormalization ()
279
+ ->ifArray ()
280
+ ->then (function (array $ v ) {
281
+ if (isset ($ v ['bool_force_cast ' ])) {
282
+ $ v ['bool_force_cast ' ] = (bool ) $ v ['bool_force_cast ' ];
283
+ }
284
+
285
+ return $ v ;
286
+ })
287
+ ->end ()
263
288
->children ()
264
289
->scalarNode ('child_node ' )->end ()
290
+ ->booleanNode ('bool_force_cast ' )->end ()
265
291
->integerNode ('int_unset_at_zero ' )
266
292
->validate ()
267
293
->ifTrue (function ($ value ) { return 0 === $ value ; })
0 commit comments