Skip to content

Commit bc15472

Browse files
committed
Prepend is now ALWAYS invoked.
1 parent 84ada52 commit bc15472

6 files changed

+76
-41
lines changed

PhpUnit/AbstractExtensionTestCase.php

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -49,15 +49,14 @@ protected function setUp()
4949
* set $withPrependInvocation to TRUE to invoke prepend() method prior to load() method of your extension.
5050
*
5151
* @param array $configurationValues
52-
* @param bool $withPrependInvocation
5352
*/
54-
protected function load(array $configurationValues = array(), $withPrependInvocation = false)
53+
protected function load(array $configurationValues = array())
5554
{
5655
$configs = array($this->getMinimalConfiguration(), $configurationValues);
5756

5857
foreach ($this->container->getExtensions() as $extension) {
5958

60-
if ($withPrependInvocation && $extension instanceof PrependExtensionInterface) {
59+
if ($extension instanceof PrependExtensionInterface) {
6160
$extension->prepend($this->container);
6261
}
6362

README.md

Lines changed: 0 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -102,26 +102,6 @@ class MyExtensionTest extends AbstractExtensionTestCase
102102
To prevent duplication of required configuration values, you can provide some minimal configuration, by overriding
103103
the ``getMinimalConfiguration()`` method of the test case.
104104

105-
If your extension implements `Symfony\Component\DependencyInjection\Extension\PrependExtensionInterface`, you may test
106-
its effect on execution by passing ``true`` as a second parameter to ``load()`` method.
107-
108-
```php
109-
<?php
110-
111-
class MyExtensionTest extends AbstractExtensionTestCase
112-
{
113-
/**
114-
* @test
115-
*/
116-
public function after_loading_the_correct_parameter_has_been_set()
117-
{
118-
$this->load(array(), true);
119-
120-
...
121-
}
122-
}
123-
```
124-
125105
## Testing a compiler pass
126106

127107
To test a compiler pass, create a test class and extend from

Tests/Fixtures/MatthiasDependencyInjectionTestExtension.php

Lines changed: 1 addition & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -5,20 +5,11 @@
55
use Symfony\Component\DependencyInjection\Definition;
66
use Symfony\Component\DependencyInjection\Extension\ExtensionInterface;
77
use Symfony\Component\DependencyInjection\ContainerBuilder;
8-
use Symfony\Component\DependencyInjection\Extension\PrependExtensionInterface;
98
use Symfony\Component\DependencyInjection\Loader\XmlFileLoader;
109
use Symfony\Component\Config\FileLocator;
1110

12-
class MatthiasDependencyInjectionTestExtension implements ExtensionInterface, PrependExtensionInterface
11+
class MatthiasDependencyInjectionTestExtension implements ExtensionInterface
1312
{
14-
/**
15-
* {@inheritdoc}
16-
*/
17-
public function prepend(ContainerBuilder $container)
18-
{
19-
$container->setParameter('prepend_extension_interface.successfully_invoked', 'prepended value');
20-
}
21-
2213
public function load(array $config, ContainerBuilder $container)
2314
{
2415
// load some service definitions
Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
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 NonPrependableTestExtension implements ExtensionInterface
9+
{
10+
public function prepend(ContainerBuilder $container)
11+
{
12+
$container->setParameter('ignored_invocation', 'ignored value');
13+
}
14+
15+
public function load(array $config, ContainerBuilder $container)
16+
{
17+
}
18+
19+
public function getAlias()
20+
{
21+
return 'non_prependable_test';
22+
}
23+
24+
public function getNamespace()
25+
{
26+
}
27+
28+
public function getXsdValidationBasePath()
29+
{
30+
}
31+
}
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 PrependableTestExtension implements ExtensionInterface, PrependExtensionInterface
10+
{
11+
public function prepend(ContainerBuilder $container)
12+
{
13+
$container->setParameter('prepend_parameter_set', 'prepended value');
14+
}
15+
16+
public function load(array $config, ContainerBuilder $container)
17+
{
18+
}
19+
20+
public function getAlias()
21+
{
22+
return 'prependable_test';
23+
}
24+
25+
public function getNamespace()
26+
{
27+
}
28+
29+
public function getXsdValidationBasePath()
30+
{
31+
}
32+
}

Tests/PhpUnit/AbstractPrependExtensionTestCaseTest.php

Lines changed: 10 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -3,38 +3,40 @@
33
namespace Matthias\DependencyInjectionTests\Test\DependencyInjection;
44

55
use Matthias\SymfonyDependencyInjectionTest\PhpUnit\AbstractExtensionTestCase;
6-
use Matthias\SymfonyDependencyInjectionTest\Tests\Fixtures\MatthiasDependencyInjectionTestExtension;
6+
use Matthias\SymfonyDependencyInjectionTest\Tests\Fixtures\NonPrependableTestExtension;
7+
use Matthias\SymfonyDependencyInjectionTest\Tests\Fixtures\PrependableTestExtension;
78
use PHPUnit\Framework\ExpectationFailedException;
89

910
class AbstractPrependExtensionTestCaseTest extends AbstractExtensionTestCase
1011
{
1112
protected function getContainerExtensions()
1213
{
1314
return array(
14-
new MatthiasDependencyInjectionTestExtension()
15+
new PrependableTestExtension(),
16+
new NonPrependableTestExtension()
1517
);
1618
}
1719

1820
/**
1921
* @test
2022
*/
21-
public function if_prepend_invoked_it_does_not_fails()
23+
public function prepend_invoked_only_if_prepend_interface_is_implemented()
2224
{
23-
$this->load([], true);
25+
$this->load();
2426

25-
$this->assertContainerBuilderHasParameter('prepend_extension_interface.successfully_invoked', 'prepended value');
27+
$this->assertContainerBuilderHasParameter('prepend_parameter_set', 'prepended value');
2628
}
2729

2830
/**
2931
* @test
3032
*/
31-
public function if_prepend_is_not_invoked_it_does_not_fails()
33+
public function if_prepend_interface_is_not_implemented_prepend_is_not_invoked()
3234
{
3335
$this->load();
3436

3537
$this->expectException(ExpectationFailedException::class);
36-
$this->expectExceptionMessage('prepend_extension_interface.successfully_invoked');
38+
$this->expectExceptionMessage('ignored_invocation');
3739

38-
$this->assertContainerBuilderHasParameter('prepend_extension_interface.successfully_invoked', 'prepended value');
40+
$this->assertContainerBuilderHasParameter('ignored_invocation', 'ignored value');
3941
}
4042
}

0 commit comments

Comments
 (0)