|
14 | 14 | use PHPUnit\Framework\TestCase;
|
15 | 15 | use Symfony\Component\Config\Definition\Builder\TreeBuilder;
|
16 | 16 | use Symfony\Component\Config\Definition\ConfigurationInterface;
|
| 17 | +use Symfony\Component\Config\Definition\Exception\TreeWithoutRootNodeException; |
17 | 18 | use Symfony\Component\DependencyInjection\Compiler\MergeExtensionConfigurationPass;
|
18 | 19 | use Symfony\Component\DependencyInjection\Compiler\RegisterEnvVarProcessorsPass;
|
19 | 20 | use Symfony\Component\DependencyInjection\Compiler\ValidateEnvPlaceholdersPass;
|
@@ -222,6 +223,17 @@ public function testEnvWithVariableNode(): void
|
222 | 223 | $this->assertSame($expected, $container->resolveEnvPlaceholders($ext->getConfig()));
|
223 | 224 | }
|
224 | 225 |
|
| 226 | + public function testConfigurationWithoutRootNode(): void |
| 227 | + { |
| 228 | + $container = new ContainerBuilder(); |
| 229 | + $container->registerExtension($ext = new EnvExtension(new EnvConfigurationWithoutRootNode())); |
| 230 | + $container->loadFromExtension('env_extension'); |
| 231 | + |
| 232 | + $this->doProcess($container); |
| 233 | + |
| 234 | + $this->addToAssertionCount(1); |
| 235 | + } |
| 236 | + |
225 | 237 | private function doProcess(ContainerBuilder $container): void
|
226 | 238 | {
|
227 | 239 | (new MergeExtensionConfigurationPass())->process($container);
|
@@ -267,23 +279,41 @@ public function getConfigTreeBuilder()
|
267 | 279 | }
|
268 | 280 | }
|
269 | 281 |
|
| 282 | +class EnvConfigurationWithoutRootNode implements ConfigurationInterface |
| 283 | +{ |
| 284 | + public function getConfigTreeBuilder() |
| 285 | + { |
| 286 | + return new TreeBuilder(); |
| 287 | + } |
| 288 | +} |
| 289 | + |
270 | 290 | class EnvExtension extends Extension
|
271 | 291 | {
|
| 292 | + private $configuration; |
272 | 293 | private $config;
|
273 | 294 |
|
| 295 | + public function __construct(ConfigurationInterface $configuration = null) |
| 296 | + { |
| 297 | + $this->configuration = $configuration ?? new EnvConfiguration(); |
| 298 | + } |
| 299 | + |
274 | 300 | public function getAlias()
|
275 | 301 | {
|
276 | 302 | return 'env_extension';
|
277 | 303 | }
|
278 | 304 |
|
279 | 305 | public function getConfiguration(array $config, ContainerBuilder $container)
|
280 | 306 | {
|
281 |
| - return new EnvConfiguration(); |
| 307 | + return $this->configuration; |
282 | 308 | }
|
283 | 309 |
|
284 | 310 | public function load(array $configs, ContainerBuilder $container)
|
285 | 311 | {
|
286 |
| - $this->config = $this->processConfiguration($this->getConfiguration($configs, $container), $configs); |
| 312 | + try { |
| 313 | + $this->config = $this->processConfiguration($this->getConfiguration($configs, $container), $configs); |
| 314 | + } catch (TreeWithoutRootNodeException $e) { |
| 315 | + $this->config = null; |
| 316 | + } |
287 | 317 | }
|
288 | 318 |
|
289 | 319 | public function getConfig()
|
|
0 commit comments