1212namespace Symfony \Component \Translation \Tests \DependencyInjection ;
1313
1414use PHPUnit \Framework \TestCase ;
15+ use Symfony \Component \DependencyInjection \ContainerBuilder ;
1516use Symfony \Component \DependencyInjection \Reference ;
1617use Symfony \Component \Translation \DependencyInjection \TranslationExtractorPass ;
1718
1819class TranslationExtractorPassTest extends TestCase
1920{
2021 public function testProcess ()
2122 {
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 ' ));
4627
4728 $ translationDumperPass = new TranslationExtractorPass ();
4829 $ translationDumperPass ->process ($ container );
30+
31+ $ this ->assertEquals (array (array ('addExtractor ' , array ('bar.alias ' , new Reference ('foo.id ' )))), $ extractorDefinition ->getMethodCalls ());
4932 }
5033
5134 public function testProcessNoDefinitionFound ()
5235 {
53- $ container = $ this -> getMockBuilder ( ' Symfony\Component\DependencyInjection\ ContainerBuilder' )-> disableOriginalConstructor ()-> getMock ();
36+ $ container = new ContainerBuilder ();
5437
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 ());
6240
6341 $ translationDumperPass = new TranslationExtractorPass ();
6442 $ 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 ());
6547 }
6648
6749 /**
@@ -71,25 +53,10 @@ public function testProcessNoDefinitionFound()
7153 public function testProcessMissingAlias ()
7254 {
7355 $ 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 ());
9360
9461 $ definition ->expects ($ this ->never ())->method ('addMethodCall ' );
9562
0 commit comments