12
12
namespace Symfony \Component \DependencyInjection \Tests \Compiler ;
13
13
14
14
use PHPUnit \Framework \TestCase ;
15
+ use Symfony \Component \Config \Definition \BaseNode ;
15
16
use Symfony \Component \Config \Definition \Builder \TreeBuilder ;
16
17
use Symfony \Component \Config \Definition \ConfigurationInterface ;
17
18
use Symfony \Component \Config \Resource \FileResource ;
@@ -128,6 +129,23 @@ public function testThrowingExtensionsGetMergedBag()
128
129
129
130
$ this ->assertSame (['FOO ' ], array_keys ($ container ->getParameterBag ()->getEnvPlaceholders ()));
130
131
}
132
+
133
+ public function testReuseEnvPlaceholderGeneratedByPreviousExtension ()
134
+ {
135
+ if (!property_exists (BaseNode::class, 'placeholderUniquePrefixes ' )) {
136
+ $ this ->markTestSkipped ('This test requires symfony/config ^4.4.11|^5.0.11|^5.1.3 ' );
137
+ }
138
+
139
+ $ container = new ContainerBuilder ();
140
+ $ container ->registerExtension (new FooExtension ());
141
+ $ container ->registerExtension (new TestCccExtension ());
142
+ $ container ->prependExtensionConfig ('foo ' , ['bool_node ' => '%env(bool:MY_ENV_VAR)% ' ]);
143
+ $ container ->prependExtensionConfig ('test_ccc ' , ['bool_node ' => '%env(bool:MY_ENV_VAR)% ' ]);
144
+
145
+ (new MergeExtensionConfigurationPass ())->process ($ container );
146
+
147
+ $ this ->addToAssertionCount (1 );
148
+ }
131
149
}
132
150
133
151
class FooConfiguration implements ConfigurationInterface
@@ -139,6 +157,7 @@ public function getConfigTreeBuilder(): TreeBuilder
139
157
->children ()
140
158
->scalarNode ('bar ' )->end ()
141
159
->scalarNode ('baz ' )->end ()
160
+ ->booleanNode ('bool_node ' )->end ()
142
161
->end ();
143
162
144
163
return $ treeBuilder ;
@@ -166,6 +185,8 @@ public function load(array $configs, ContainerBuilder $container)
166
185
$ container ->getParameterBag ()->get ('env(BOZ) ' );
167
186
$ container ->resolveEnvPlaceholders ($ config ['baz ' ]);
168
187
}
188
+
189
+ $ container ->setParameter ('foo.param ' , 'ccc ' );
169
190
}
170
191
}
171
192
@@ -194,3 +215,36 @@ public function load(array $configs, ContainerBuilder $container)
194
215
throw new \Exception ();
195
216
}
196
217
}
218
+
219
+ final class TestCccConfiguration implements ConfigurationInterface
220
+ {
221
+ public function getConfigTreeBuilder (): TreeBuilder
222
+ {
223
+ $ treeBuilder = new TreeBuilder ('test_ccc ' );
224
+ $ treeBuilder ->getRootNode ()
225
+ ->children ()
226
+ ->booleanNode ('bool_node ' )->end ()
227
+ ->end ();
228
+
229
+ return $ treeBuilder ;
230
+ }
231
+ }
232
+
233
+ final class TestCccExtension extends Extension
234
+ {
235
+ public function getAlias (): string
236
+ {
237
+ return 'test_ccc ' ;
238
+ }
239
+
240
+ public function getConfiguration (array $ config , ContainerBuilder $ container ): ?ConfigurationInterface
241
+ {
242
+ return new TestCccConfiguration ();
243
+ }
244
+
245
+ public function load (array $ configs , ContainerBuilder $ container )
246
+ {
247
+ $ configuration = $ this ->getConfiguration ($ configs , $ container );
248
+ $ this ->processConfiguration ($ configuration , $ configs );
249
+ }
250
+ }
0 commit comments