12
12
namespace Symfony \Component \Translation \Tests \DependencyInjection ;
13
13
14
14
use PHPUnit \Framework \TestCase ;
15
+ use Symfony \Component \DependencyInjection \ContainerBuilder ;
15
16
use Symfony \Component \DependencyInjection \Reference ;
16
17
use Symfony \Component \Translation \DependencyInjection \TranslationExtractorPass ;
17
18
18
19
class TranslationExtractorPassTest extends TestCase
19
20
{
20
21
public function testProcess ()
21
22
{
22
- $ definition = $ this ->getMockBuilder ('Symfony\Component\DependencyInjection\Definition ' )->disableOriginalConstructor ()->getMock ();
23
- $ container = $ this ->getMockBuilder ('Symfony\Component\DependencyInjection\ContainerBuilder ' )->disableOriginalConstructor ()->getMock ();
24
-
25
- $ container ->expects ($ this ->once ())
26
- ->method ('hasDefinition ' )
27
- ->with ('translation.extractor ' )
28
- ->will ($ this ->returnValue (true ));
29
-
30
- $ container ->expects ($ this ->once ())
31
- ->method ('getDefinition ' )
32
- ->with ('translation.extractor ' )
33
- ->will ($ this ->returnValue ($ definition ));
34
-
35
- $ valueTaggedServiceIdsFound = array (
36
- 'foo.id ' => array (
37
- array ('alias ' => 'bar.alias ' ),
38
- ),
39
- );
40
- $ container ->expects ($ this ->once ())
41
- ->method ('findTaggedServiceIds ' )
42
- ->with ('translation.extractor ' , true )
43
- ->will ($ this ->returnValue ($ valueTaggedServiceIdsFound ));
44
-
45
- $ definition ->expects ($ this ->once ())->method ('addMethodCall ' )->with ('addExtractor ' , array ('bar.alias ' , new Reference ('foo.id ' )));
23
+ $ container = new ContainerBuilder ();
24
+ $ extractorDefinition = $ container ->register ('translation.extractor ' );
25
+ $ container ->register ('foo.id ' )
26
+ ->addTag ('translation.extractor ' , array ('alias ' => 'bar.alias ' ));
46
27
47
28
$ translationDumperPass = new TranslationExtractorPass ();
48
29
$ translationDumperPass ->process ($ container );
30
+
31
+ $ this ->assertEquals (array (array ('addExtractor ' , array ('bar.alias ' , new Reference ('foo.id ' )))), $ extractorDefinition ->getMethodCalls ());
49
32
}
50
33
51
34
public function testProcessNoDefinitionFound ()
52
35
{
53
- $ container = $ this -> getMockBuilder ( ' Symfony\Component\DependencyInjection\ ContainerBuilder' )-> disableOriginalConstructor ()-> getMock ();
36
+ $ container = new ContainerBuilder ();
54
37
55
- $ container ->expects ($ this ->once ())
56
- ->method ('hasDefinition ' )
57
- ->with ('translation.extractor ' )
58
- ->will ($ this ->returnValue (false ));
59
-
60
- $ container ->expects ($ this ->never ())->method ('getDefinition ' );
61
- $ container ->expects ($ this ->never ())->method ('findTaggedServiceIds ' );
38
+ $ definitionsBefore = count ($ container ->getDefinitions ());
39
+ $ aliasesBefore = count ($ container ->getAliases ());
62
40
63
41
$ translationDumperPass = new TranslationExtractorPass ();
64
42
$ translationDumperPass ->process ($ container );
43
+
44
+ // the container is untouched (i.e. no new definitions or aliases)
45
+ $ this ->assertCount ($ definitionsBefore , $ container ->getDefinitions ());
46
+ $ this ->assertCount ($ aliasesBefore , $ container ->getAliases ());
65
47
}
66
48
67
49
/**
@@ -71,25 +53,10 @@ public function testProcessNoDefinitionFound()
71
53
public function testProcessMissingAlias ()
72
54
{
73
55
$ definition = $ this ->getMockBuilder ('Symfony\Component\DependencyInjection\Definition ' )->disableOriginalConstructor ()->getMock ();
74
- $ container = $ this ->getMockBuilder ('Symfony\Component\DependencyInjection\ContainerBuilder ' )->disableOriginalConstructor ()->getMock ();
75
-
76
- $ container ->expects ($ this ->once ())
77
- ->method ('hasDefinition ' )
78
- ->with ('translation.extractor ' )
79
- ->will ($ this ->returnValue (true ));
80
-
81
- $ container ->expects ($ this ->once ())
82
- ->method ('getDefinition ' )
83
- ->with ('translation.extractor ' )
84
- ->will ($ this ->returnValue ($ definition ));
85
-
86
- $ valueTaggedServiceIdsFound = array (
87
- 'foo.id ' => array (),
88
- );
89
- $ container ->expects ($ this ->once ())
90
- ->method ('findTaggedServiceIds ' )
91
- ->with ('translation.extractor ' , true )
92
- ->will ($ this ->returnValue ($ valueTaggedServiceIdsFound ));
56
+ $ container = new ContainerBuilder ();
57
+ $ container ->register ('translation.extractor ' );
58
+ $ container ->register ('foo.id ' )
59
+ ->addTag ('translation.extractor ' , array ());
93
60
94
61
$ definition ->expects ($ this ->never ())->method ('addMethodCall ' );
95
62
0 commit comments