12
12
namespace Symfony \Component \DependencyInjection \Tests \Compiler ;
13
13
14
14
use PHPUnit \Framework \TestCase ;
15
+ use Symfony \Component \DependencyInjection \Compiler \CompilerPassInterface ;
15
16
use Symfony \Component \DependencyInjection \Compiler \ExtensionCompilerPass ;
17
+ use Symfony \Component \DependencyInjection \ContainerBuilder ;
18
+ use Symfony \Component \DependencyInjection \Extension \Extension ;
16
19
17
20
/**
18
21
* @author Wouter J <wouter@wouterj.nl>
@@ -24,33 +27,55 @@ class ExtensionCompilerPassTest extends TestCase
24
27
25
28
protected function setUp ()
26
29
{
27
- $ this ->container = $ this -> getMockBuilder ( ' Symfony\Component\DependencyInjection\ ContainerBuilder' )-> getMock ();
30
+ $ this ->container = new ContainerBuilder ();
28
31
$ this ->pass = new ExtensionCompilerPass ();
29
32
}
30
33
31
34
public function testProcess ()
32
35
{
33
- $ extension1 = $ this ->createExtensionMock (true );
34
- $ extension1 ->expects ($ this ->once ())->method ('process ' );
35
- $ extension2 = $ this ->createExtensionMock (false );
36
- $ extension3 = $ this ->createExtensionMock (false );
37
- $ extension4 = $ this ->createExtensionMock (true );
38
- $ extension4 ->expects ($ this ->once ())->method ('process ' );
39
-
40
- $ this ->container ->expects ($ this ->any ())
41
- ->method ('getExtensions ' )
42
- ->will ($ this ->returnValue (array ($ extension1 , $ extension2 , $ extension3 , $ extension4 )))
43
- ;
36
+ $ extension1 = new CompilerPassExtension ('extension1 ' );
37
+ $ extension2 = new DummyExtension ('extension2 ' );
38
+ $ extension3 = new DummyExtension ('extension3 ' );
39
+ $ extension4 = new CompilerPassExtension ('extension4 ' );
40
+
41
+ $ this ->container ->registerExtension ($ extension1 );
42
+ $ this ->container ->registerExtension ($ extension2 );
43
+ $ this ->container ->registerExtension ($ extension3 );
44
+ $ this ->container ->registerExtension ($ extension4 );
44
45
45
46
$ this ->pass ->process ($ this ->container );
47
+
48
+ $ this ->assertTrue ($ this ->container ->hasDefinition ('extension1 ' ));
49
+ $ this ->assertFalse ($ this ->container ->hasDefinition ('extension2 ' ));
50
+ $ this ->assertFalse ($ this ->container ->hasDefinition ('extension3 ' ));
51
+ $ this ->assertTrue ($ this ->container ->hasDefinition ('extension4 ' ));
46
52
}
53
+ }
54
+
55
+ class DummyExtension extends Extension
56
+ {
57
+ private $ alias ;
47
58
48
- private function createExtensionMock ( $ hasInlineCompile )
59
+ public function __construct ( $ alias )
49
60
{
50
- return $ this ->getMockBuilder ('Symfony\Component\DependencyInjection \\' .(
51
- $ hasInlineCompile
52
- ? 'Compiler\CompilerPassInterface '
53
- : 'Extension\ExtensionInterface '
54
- ))->getMock ();
61
+ $ this ->alias = $ alias ;
55
62
}
63
+
64
+ public function getAlias ()
65
+ {
66
+ return $ this ->alias ;
67
+ }
68
+
69
+ public function load (array $ configs , ContainerBuilder $ container )
70
+ {
71
+ }
72
+
73
+ public function process (ContainerBuilder $ container )
74
+ {
75
+ $ container ->register ($ this ->alias );
76
+ }
77
+ }
78
+
79
+ class CompilerPassExtension extends DummyExtension implements CompilerPassInterface
80
+ {
56
81
}
0 commit comments