Skip to content

Commit d650140

Browse files
authored
Fix executing prepend first with multiple extensions (#126)
1 parent 72898ed commit d650140

File tree

4 files changed

+91
-0
lines changed

4 files changed

+91
-0
lines changed

PhpUnit/AbstractExtensionTestCase.php

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -53,7 +53,9 @@ final protected function load(array $configurationValues = []): void
5353
if ($extension instanceof PrependExtensionInterface) {
5454
$extension->prepend($this->container);
5555
}
56+
}
5657

58+
foreach ($this->container->getExtensions() as $extension) {
5759
$extension->load($configs, $this->container);
5860
}
5961
}
Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
<?php
2+
3+
namespace Matthias\SymfonyDependencyInjectionTest\Tests\Fixtures;
4+
5+
use Symfony\Component\DependencyInjection\ContainerBuilder;
6+
use Symfony\Component\DependencyInjection\Extension\ExtensionInterface;
7+
8+
class DependableExtension implements ExtensionInterface
9+
{
10+
public function load(array $config, ContainerBuilder $container): void
11+
{
12+
if ($container->hasParameter('parameter_from_non_dependable')) {
13+
$container->setParameter('dependable_parameter', 'dependable value');
14+
}
15+
}
16+
17+
public function getAlias()
18+
{
19+
return 'dependable';
20+
}
21+
22+
public function getNamespace(): void
23+
{
24+
}
25+
26+
public function getXsdValidationBasePath(): void
27+
{
28+
}
29+
}
Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
<?php
2+
3+
namespace Matthias\SymfonyDependencyInjectionTest\Tests\Fixtures;
4+
5+
use Symfony\Component\DependencyInjection\ContainerBuilder;
6+
use Symfony\Component\DependencyInjection\Extension\ExtensionInterface;
7+
use Symfony\Component\DependencyInjection\Extension\PrependExtensionInterface;
8+
9+
class NonDependablePrependableExtension implements ExtensionInterface, PrependExtensionInterface
10+
{
11+
public function load(array $config, ContainerBuilder $container): void
12+
{
13+
}
14+
15+
public function getAlias()
16+
{
17+
return 'non_dependable';
18+
}
19+
20+
public function getNamespace(): void
21+
{
22+
}
23+
24+
public function getXsdValidationBasePath(): void
25+
{
26+
}
27+
28+
public function prepend(ContainerBuilder $container)
29+
{
30+
$container->setParameter('parameter_from_non_dependable', 'non-dependable value');
31+
}
32+
}
Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
<?php
2+
3+
namespace Matthias\DependencyInjectionTests\Test\DependencyInjection;
4+
5+
use Matthias\SymfonyDependencyInjectionTest\PhpUnit\AbstractExtensionTestCase;
6+
use Matthias\SymfonyDependencyInjectionTest\Tests\Fixtures\DependableExtension;
7+
use Matthias\SymfonyDependencyInjectionTest\Tests\Fixtures\NonDependablePrependableExtension;
8+
9+
class AbstractDependableExtensionTestCaseTest extends AbstractExtensionTestCase
10+
{
11+
protected function getContainerExtensions(): array
12+
{
13+
return [
14+
new DependableExtension(),
15+
new NonDependablePrependableExtension(),
16+
];
17+
}
18+
19+
/**
20+
* @test
21+
*/
22+
public function prepend_invoked_before_any_load(): void
23+
{
24+
$this->load();
25+
26+
$this->assertContainerBuilderHasParameter('dependable_parameter', 'dependable value');
27+
}
28+
}

0 commit comments

Comments
 (0)