Skip to content

Commit

Permalink
minor #27915 [DependencyInjection] add missing test for #27710 (xabbuh)
Browse files Browse the repository at this point in the history
This PR was merged into the 4.1 branch.

Discussion
----------

[DependencyInjection] add missing test for #27710

| Q             | A
| ------------- | ---
| Branch?       | 4.1
| Bug fix?      | no
| New feature?  | no
| BC breaks?    | no
| Deprecations? | no
| Tests pass?   | yes
| Fixed tickets | #27710 (review)
| License       | MIT
| Doc PR        |

Commits
-------

a265caf [DependencyInjection] add missing test for #27710
  • Loading branch information
fabpot committed Jul 12, 2018
2 parents a552e84 + a265caf commit 4f1647e
Showing 1 changed file with 34 additions and 0 deletions.
Expand Up @@ -234,6 +234,18 @@ public function testConfigurationWithoutRootNode(): void
$this->addToAssertionCount(1);
}

public function testEmptyConfigFromMoreThanOneSource()
{
$container = new ContainerBuilder();
$container->registerExtension(new EnvExtension(new ConfigurationWithArrayNodeRequiringOneElement()));
$container->loadFromExtension('env_extension', array());
$container->loadFromExtension('env_extension', array());

$this->doProcess($container);

$this->addToAssertionCount(1);
}

public function testDiscardedEnvInConfig(): void
{
$container = new ContainerBuilder();
Expand Down Expand Up @@ -313,6 +325,24 @@ public function getConfigTreeBuilder()
}
}

class ConfigurationWithArrayNodeRequiringOneElement implements ConfigurationInterface
{
public function getConfigTreeBuilder()
{
$treeBuilder = new TreeBuilder();
$treeBuilder->root('env_extension')
->children()
->arrayNode('nodes')
->isRequired()
->requiresAtLeastOneElement()
->scalarPrototype()->end()
->end()
->end();

return $treeBuilder;
}
}

class EnvExtension extends Extension
{
private $configuration;
Expand All @@ -335,6 +365,10 @@ public function getConfiguration(array $config, ContainerBuilder $container)

public function load(array $configs, ContainerBuilder $container)
{
if (!array_filter($configs)) {
return;
}

try {
$this->config = $this->processConfiguration($this->getConfiguration($configs, $container), $configs);
} catch (TreeWithoutRootNodeException $e) {
Expand Down

0 comments on commit 4f1647e

Please sign in to comment.