@@ -26,38 +26,78 @@ public function testDebugMissingMessages()
26
26
$ tester = $ this ->createCommandTester ($ this ->getContainer (array ('foo ' => 'foo ' )));
27
27
$ tester ->execute (array ('locale ' => 'en ' , 'bundle ' => 'foo ' ));
28
28
29
- $ this ->assertRegExp ('/x (\s|\|)+foo / ' , $ tester ->getDisplay (), ' Display x in case of missing message ' );
29
+ $ this ->assertRegExp ('/missing / ' , $ tester ->getDisplay ());
30
30
}
31
31
32
32
public function testDebugUnusedMessages ()
33
33
{
34
34
$ tester = $ this ->createCommandTester ($ this ->getContainer (array (), array ('foo ' => 'foo ' )));
35
35
$ tester ->execute (array ('locale ' => 'en ' , 'bundle ' => 'foo ' ));
36
36
37
- $ this ->assertRegExp ('/o (\s|\|)+foo / ' , $ tester ->getDisplay (), ' Display o in case of unused message ' );
37
+ $ this ->assertRegExp ('/unused / ' , $ tester ->getDisplay ());
38
38
}
39
39
40
40
public function testDebugFallbackMessages ()
41
41
{
42
42
$ tester = $ this ->createCommandTester ($ this ->getContainer (array (), array ('foo ' => 'foo ' )));
43
43
$ tester ->execute (array ('locale ' => 'fr ' , 'bundle ' => 'foo ' ));
44
44
45
- $ this ->assertRegExp ('/= (\s|\|)+foo / ' , $ tester ->getDisplay (), ' Display = in case of fallback message ' );
45
+ $ this ->assertRegExp ('/fallback / ' , $ tester ->getDisplay ());
46
46
}
47
47
48
48
public function testNoDefinedMessages ()
49
49
{
50
50
$ tester = $ this ->createCommandTester ($ this ->getContainer ());
51
51
$ tester ->execute (array ('locale ' => 'fr ' , 'bundle ' => 'test ' ));
52
52
53
- $ this ->assertRegExp ('/^No defined or extracted messages for locale "fr"/ ' , $ tester ->getDisplay ());
53
+ $ this ->assertRegExp ('/No defined or extracted messages for locale "fr"/ ' , $ tester ->getDisplay ());
54
+ }
55
+
56
+ public function testDebugDefaultDirectory ()
57
+ {
58
+ $ tester = $ this ->createCommandTester ($ this ->getContainer (array ('foo ' => 'foo ' ), array ('bar ' => 'bar ' )));
59
+ $ tester ->execute (array ('locale ' => 'en ' ));
60
+
61
+ $ this ->assertRegExp ('/missing/ ' , $ tester ->getDisplay ());
62
+ $ this ->assertRegExp ('/unused/ ' , $ tester ->getDisplay ());
63
+ }
64
+
65
+ public function testDebugCustomDirectory ()
66
+ {
67
+ $ kernel = $ this ->getMock ('Symfony\Component\HttpKernel\KernelInterface ' );
68
+ $ kernel ->expects ($ this ->once ())
69
+ ->method ('getBundle ' )
70
+ ->with ($ this ->equalTo ($ this ->translationDir ))
71
+ ->willThrowException (new \InvalidArgumentException ());
72
+
73
+ $ tester = $ this ->createCommandTester ($ this ->getContainer (array ('foo ' => 'foo ' ), array ('bar ' => 'bar ' ), $ kernel ));
74
+ $ tester ->execute (array ('locale ' => 'en ' , 'bundle ' => $ this ->translationDir ));
75
+
76
+ $ this ->assertRegExp ('/missing/ ' , $ tester ->getDisplay ());
77
+ $ this ->assertRegExp ('/unused/ ' , $ tester ->getDisplay ());
78
+ }
79
+
80
+ /**
81
+ * @expectedException \InvalidArgumentException
82
+ */
83
+ public function testDebugInvalidDirectory ()
84
+ {
85
+ $ kernel = $ this ->getMock ('Symfony\Component\HttpKernel\KernelInterface ' );
86
+ $ kernel ->expects ($ this ->once ())
87
+ ->method ('getBundle ' )
88
+ ->with ($ this ->equalTo ('dir ' ))
89
+ ->will ($ this ->throwException (new \InvalidArgumentException ()));
90
+
91
+ $ tester = $ this ->createCommandTester ($ this ->getContainer (array (), array (), $ kernel ));
92
+ $ tester ->execute (array ('locale ' => 'en ' , 'bundle ' => 'dir ' ));
54
93
}
55
94
56
95
protected function setUp ()
57
96
{
58
97
$ this ->fs = new Filesystem ();
59
98
$ this ->translationDir = sys_get_temp_dir ().'/ ' .uniqid ('sf2_translation ' );
60
99
$ this ->fs ->mkdir ($ this ->translationDir .'/Resources/translations ' );
100
+ $ this ->fs ->mkdir ($ this ->translationDir .'/Resources/views ' );
61
101
}
62
102
63
103
protected function tearDown ()
@@ -79,7 +119,7 @@ private function createCommandTester($container)
79
119
return new CommandTester ($ application ->find ('debug:translation ' ));
80
120
}
81
121
82
- private function getContainer ($ extractedMessages = array (), $ loadedMessages = array ())
122
+ private function getContainer ($ extractedMessages = array (), $ loadedMessages = array (), $ kernel = null )
83
123
{
84
124
$ translator = $ this ->getMockBuilder ('Symfony\Component\Translation\Translator ' )
85
125
->disableOriginalConstructor ()
@@ -110,14 +150,21 @@ private function getContainer($extractedMessages = array(), $loadedMessages = ar
110
150
})
111
151
);
112
152
113
- $ kernel = $ this ->getMock ('Symfony\Component\HttpKernel\KernelInterface ' );
153
+ if (null === $ kernel ) {
154
+ $ kernel = $ this ->getMock ('Symfony\Component\HttpKernel\KernelInterface ' );
155
+ $ kernel
156
+ ->expects ($ this ->any ())
157
+ ->method ('getBundle ' )
158
+ ->will ($ this ->returnValueMap (array (
159
+ array ('foo ' , true , $ this ->getBundle ($ this ->translationDir )),
160
+ array ('test ' , true , $ this ->getBundle ('test ' )),
161
+ )));
162
+ }
163
+
114
164
$ kernel
115
165
->expects ($ this ->any ())
116
- ->method ('getBundle ' )
117
- ->will ($ this ->returnValueMap (array (
118
- array ('foo ' , true , $ this ->getBundle ($ this ->translationDir )),
119
- array ('test ' , true , $ this ->getBundle ('test ' )),
120
- )));
166
+ ->method ('getRootDir ' )
167
+ ->will ($ this ->returnValue ($ this ->translationDir ));
121
168
122
169
$ container = $ this ->getMock ('Symfony\Component\DependencyInjection\ContainerInterface ' );
123
170
$ container
0 commit comments