1212namespace Symfony \Component \DependencyInjection \Tests \Compiler ;
1313
1414use PHPUnit \Framework \TestCase ;
15+ use Symfony \Component \DependencyInjection \Compiler \CompilerPassInterface ;
1516use Symfony \Component \DependencyInjection \Compiler \ExtensionCompilerPass ;
17+ use Symfony \Component \DependencyInjection \ContainerBuilder ;
18+ use Symfony \Component \DependencyInjection \Extension \Extension ;
1619
1720/**
1821 * @author Wouter J <wouter@wouterj.nl>
@@ -24,33 +27,55 @@ class ExtensionCompilerPassTest extends TestCase
2427
2528 protected function setUp ()
2629 {
27- $ this ->container = $ this -> getMockBuilder ( ' Symfony\Component\DependencyInjection\ ContainerBuilder' )-> getMock ();
30+ $ this ->container = new ContainerBuilder ();
2831 $ this ->pass = new ExtensionCompilerPass ();
2932 }
3033
3134 public function testProcess ()
3235 {
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 );
4445
4546 $ 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 ' ));
4652 }
53+ }
54+
55+ class DummyExtension extends Extension
56+ {
57+ private $ alias ;
4758
48- private function createExtensionMock ( $ hasInlineCompile )
59+ public function __construct ( $ alias )
4960 {
50- return $ this ->getMockBuilder ('Symfony\Component\DependencyInjection \\' .(
51- $ hasInlineCompile
52- ? 'Compiler\CompilerPassInterface '
53- : 'Extension\ExtensionInterface '
54- ))->getMock ();
61+ $ this ->alias = $ alias ;
5562 }
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+ {
5681}
0 commit comments