File tree Expand file tree Collapse file tree 4 files changed +115
-1
lines changed Expand file tree Collapse file tree 4 files changed +115
-1
lines changed Original file line number Diff line number Diff line change 3
3
namespace Matthias \SymfonyDependencyInjectionTest \PhpUnit ;
4
4
5
5
use Symfony \Component \DependencyInjection \Extension \ExtensionInterface ;
6
+ use Symfony \Component \DependencyInjection \Extension \PrependExtensionInterface ;
6
7
7
8
abstract class AbstractExtensionTestCase extends AbstractContainerBuilderTestCase
8
9
{
@@ -44,13 +45,21 @@ protected function setUp()
44
45
* Call this method from within your test after you have (optionally) modified the ContainerBuilder for this test
45
46
* ($this->container).
46
47
*
47
- * @param array $specificConfiguration
48
+ * If your extension(s) implements \Symfony\Component\DependencyInjection\Extension\PrependExtensionInterface, you may
49
+ * set $withPrependInvocation to TRUE to invoke prepend() method prior to load() method of your extension.
50
+ *
51
+ * @param array $configurationValues
48
52
*/
49
53
protected function load (array $ configurationValues = array ())
50
54
{
51
55
$ configs = array ($ this ->getMinimalConfiguration (), $ configurationValues );
52
56
53
57
foreach ($ this ->container ->getExtensions () as $ extension ) {
58
+
59
+ if ($ extension instanceof PrependExtensionInterface) {
60
+ $ extension ->prepend ($ this ->container );
61
+ }
62
+
54
63
$ extension ->load ($ configs , $ this ->container );
55
64
}
56
65
}
Original file line number Diff line number Diff line change
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
+ }
Original file line number Diff line number Diff line change
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
+ }
Original file line number Diff line number Diff line change
1
+ <?php
2
+
3
+ namespace Matthias \DependencyInjectionTests \Test \DependencyInjection ;
4
+
5
+ use Matthias \SymfonyDependencyInjectionTest \PhpUnit \AbstractExtensionTestCase ;
6
+ use Matthias \SymfonyDependencyInjectionTest \Tests \Fixtures \NonPrependableTestExtension ;
7
+ use Matthias \SymfonyDependencyInjectionTest \Tests \Fixtures \PrependableTestExtension ;
8
+ use PHPUnit \Framework \ExpectationFailedException ;
9
+
10
+ class AbstractPrependExtensionTestCaseTest extends AbstractExtensionTestCase
11
+ {
12
+ protected function getContainerExtensions ()
13
+ {
14
+ return array (
15
+ new PrependableTestExtension (),
16
+ new NonPrependableTestExtension ()
17
+ );
18
+ }
19
+
20
+ /**
21
+ * @test
22
+ */
23
+ public function prepend_invoked_only_if_prepend_interface_is_implemented ()
24
+ {
25
+ $ this ->load ();
26
+
27
+ $ this ->assertContainerBuilderHasParameter ('prepend_parameter_set ' , 'prepended value ' );
28
+ }
29
+
30
+ /**
31
+ * @test
32
+ */
33
+ public function if_prepend_interface_is_not_implemented_prepend_is_not_invoked ()
34
+ {
35
+ $ this ->load ();
36
+
37
+ $ this ->expectException (ExpectationFailedException::class);
38
+ $ this ->expectExceptionMessage ('ignored_invocation ' );
39
+
40
+ $ this ->assertContainerBuilderHasParameter ('ignored_invocation ' , 'ignored value ' );
41
+ }
42
+ }
You can’t perform that action at this time.
0 commit comments