File tree Expand file tree Collapse file tree 2 files changed +34
-2
lines changed
DependencyInjection/Compiler
Tests/DependencyInjection/Compiler Expand file tree Collapse file tree 2 files changed +34
-2
lines changed Original file line number Diff line number Diff line change @@ -13,11 +13,21 @@ class AddTemplatePathPass implements CompilerPassInterface
13
13
{
14
14
public function process (ContainerBuilder $ container )
15
15
{
16
- if (!$ container ->hasDefinition ('twig.loader ' )) {
16
+ $ loaderDefinition = null ;
17
+
18
+ if ($ container ->hasDefinition ('twig.loader.filesystem ' )) {
19
+ $ loaderDefinition = $ container ->getDefinition ('twig.loader.filesystem ' );
20
+ } elseif ($ container ->hasDefinition ('twig.loader ' )) {
21
+ // Symfony 2.0 and 2.1 were not using an alias for the filesystem loader
22
+ $ loaderDefinition = $ container ->getDefinition ('twig.loader ' );
23
+ }
24
+
25
+ if (null === $ loaderDefinition ) {
17
26
return ;
18
27
}
28
+
19
29
$ refl = new \ReflectionClass ('Knp\Menu\ItemInterface ' );
20
30
$ path = dirname ($ refl ->getFileName ()).'/Resources/views ' ;
21
- $ container -> getDefinition ( ' twig.loader ' ) ->addMethodCall ('addPath ' , array ($ path ));
31
+ $ loaderDefinition ->addMethodCall ('addPath ' , array ($ path ));
22
32
}
23
33
}
Original file line number Diff line number Diff line change @@ -33,6 +33,28 @@ public function testProcess()
33
33
$ containerBuilderMock ->expects ($ this ->once ())
34
34
->method ('hasDefinition ' )
35
35
->will ($ this ->returnValue (true ));
36
+ $ containerBuilderMock ->expects ($ this ->once ())
37
+ ->method ('getDefinition ' )
38
+ ->with ($ this ->equalTo ('twig.loader.filesystem ' ))
39
+ ->will ($ this ->returnValue ($ definitionMock ));
40
+
41
+ $ templatePathPass = new AddTemplatePathPass ();
42
+ $ templatePathPass ->process ($ containerBuilderMock );
43
+ }
44
+
45
+ public function testProcessLegacy ()
46
+ {
47
+ $ definitionMock = $ this ->getMockBuilder ('Symfony\Component\DependencyInjection\Definition ' )
48
+ ->disableOriginalConstructor ()
49
+ ->getMock ();
50
+ $ definitionMock ->expects ($ this ->once ())
51
+ ->method ('addMethodCall ' )
52
+ ->with ($ this ->equalTo ('addPath ' ), $ this ->isType ('array ' ));
53
+
54
+ $ containerBuilderMock = $ this ->getMock ('Symfony\Component\DependencyInjection\ContainerBuilder ' );
55
+ $ containerBuilderMock ->expects ($ this ->exactly (2 ))
56
+ ->method ('hasDefinition ' )
57
+ ->will ($ this ->onConsecutiveCalls (false , true ));
36
58
$ containerBuilderMock ->expects ($ this ->once ())
37
59
->method ('getDefinition ' )
38
60
->with ($ this ->equalTo ('twig.loader ' ))
You can’t perform that action at this time.
0 commit comments