21
21
use Symfony \Component \HttpKernel \KernelInterface ;
22
22
use Symfony \Component \Translation \Extractor \ExtractorInterface ;
23
23
use Symfony \Component \Translation \MessageCatalogue ;
24
+ use Symfony \Component \Translation \MessageCatalogueInterface ;
24
25
use Symfony \Component \Translation \Reader \TranslationReader ;
25
26
use Symfony \Component \Translation \Translator ;
26
27
use Symfony \Component \Translation \Writer \TranslationWriter ;
@@ -79,7 +80,7 @@ public function testDumpWrongSortAndClean()
79
80
80
81
public function testDumpMessagesAndCleanInRootDirectory ()
81
82
{
82
- $ tester = $ this ->createCommandTester (['messages ' => ['foo ' => 'foo ' ]], [], null , [$ this ->translationDir . '/trans ' ], [$ this ->translationDir . '/views ' ]);
83
+ $ tester = $ this ->createCommandTester (['messages ' => ['foo ' => 'foo ' ]], [], null , [$ this ->translationDir . '/trans ' ], [$ this ->translationDir . '/views ' ]);
83
84
$ tester ->execute (['command ' => 'translation:extract ' , 'locale ' => 'en ' , '--dump-messages ' => true , '--clean ' => true ]);
84
85
$ this ->assertMatchesRegularExpression ('/foo/ ' , $ tester ->getDisplay ());
85
86
$ this ->assertMatchesRegularExpression ('/1 message was successfully extracted/ ' , $ tester ->getDisplay ());
@@ -140,10 +141,10 @@ public function testWriteMessagesForSpecificDomain()
140
141
public function testFilterDuplicateTransPaths ()
141
142
{
142
143
$ transPaths = [
143
- $ this ->translationDir . '/a/test/folder/with/a/subfolder ' ,
144
- $ this ->translationDir . '/a/test/folder/ ' ,
145
- $ this ->translationDir . '/a/test/folder/with/a/subfolder/and/a/file.txt ' ,
146
- $ this ->translationDir . '/a/different/test/folder ' ,
144
+ $ this ->translationDir . '/a/test/folder/with/a/subfolder ' ,
145
+ $ this ->translationDir . '/a/test/folder/ ' ,
146
+ $ this ->translationDir . '/a/test/folder/with/a/subfolder/and/a/file.txt ' ,
147
+ $ this ->translationDir . '/a/different/test/folder ' ,
147
148
];
148
149
149
150
foreach ($ transPaths as $ transPath ) {
@@ -169,20 +170,60 @@ public function testFilterDuplicateTransPaths()
169
170
$ filteredTransPaths = $ method ->invoke ($ command , $ transPaths );
170
171
171
172
$ expectedPaths = [
172
- realpath ($ this ->translationDir . '/a/different/test/folder ' ),
173
- realpath ($ this ->translationDir . '/a/test/folder ' ),
173
+ realpath ($ this ->translationDir . '/a/different/test/folder ' ),
174
+ realpath ($ this ->translationDir . '/a/test/folder ' ),
174
175
];
175
176
176
177
$ this ->assertEquals ($ expectedPaths , $ filteredTransPaths );
177
178
}
178
179
180
+ /**
181
+ * @dataProvider removeNoFillProvider
182
+ */
183
+ public function testRemoveNoFillTranslationsMethod ($ noFillCounter , $ messages )
184
+ {
185
+ // Preparing mock
186
+ $ operation = $ this ->createMock (MessageCatalogueInterface::class);
187
+ $ operation
188
+ ->method ('all ' )
189
+ ->with ('messages ' )
190
+ ->willReturn ($ messages );
191
+ $ operation
192
+ ->expects ($ this ->exactly ($ noFillCounter ))
193
+ ->method ('set ' );
194
+
195
+ // Calling private method
196
+ $ translationUpdate = $ this ->createMock (TranslationUpdateCommand::class);
197
+ $ reflection = new \ReflectionObject ($ translationUpdate );
198
+ $ method = $ reflection ->getMethod ('removeNoFillTranslations ' );
199
+ $ method ->setAccessible (true );
200
+ $ method ->invokeArgs ($ translationUpdate , [$ operation ]);
201
+ }
202
+
203
+ public function removeNoFillProvider (): array
204
+ {
205
+ return [
206
+ [0 , []],
207
+ [0 , ['foo ' => 'foo ' , 'bar ' => 'bar ' , 'baz ' => 'baz ' ]],
208
+ [0 , ['foo ' => "\0foo " ]],
209
+ [0 , ['foo ' => "foo \0NoFill \0" ]],
210
+ [0 , ['foo ' => "f \0NoFill \000" ]],
211
+ [0 , ['foo ' => "foo " , 'bar ' => 'bar ' ]],
212
+ [1 , ['foo ' => "\0NoFill \0foo " ]],
213
+ [1 , ['foo ' => "\0NoFill \0foo " , 'bar ' => 'bar ' ]],
214
+ [1 , ['foo ' => "foo " , 'bar ' => "\0NoFill \0bar " ]],
215
+ [2 , ['foo ' => "\0NoFill \0foo " , 'bar ' => "\0NoFill \0bar " ]],
216
+ [3 , ['foo ' => "\0NoFill \0foo " , 'bar ' => "\0NoFill \0bar " , 'baz ' => "\0NoFill \0baz " ]],
217
+ ];
218
+ }
219
+
179
220
protected function setUp (): void
180
221
{
181
222
$ this ->fs = new Filesystem ();
182
223
$ this ->translationDir = tempnam (sys_get_temp_dir (), 'sf_translation_ ' );
183
224
$ this ->fs ->remove ($ this ->translationDir );
184
- $ this ->fs ->mkdir ($ this ->translationDir . '/translations ' );
185
- $ this ->fs ->mkdir ($ this ->translationDir . '/templates ' );
225
+ $ this ->fs ->mkdir ($ this ->translationDir . '/translations ' );
226
+ $ this ->fs ->mkdir ($ this ->translationDir . '/templates ' );
186
227
}
187
228
188
229
protected function tearDown (): void
@@ -261,7 +302,7 @@ function (MessageCatalogue $catalogue) use ($writerMessages) {
261
302
->method ('getContainer ' )
262
303
->willReturn ($ container );
263
304
264
- $ command = new TranslationUpdateCommand ($ writer , $ loader , $ extractor , 'en ' , $ this ->translationDir . '/translations ' , $ this ->translationDir . '/templates ' , $ transPaths , $ codePaths );
305
+ $ command = new TranslationUpdateCommand ($ writer , $ loader , $ extractor , 'en ' , $ this ->translationDir . '/translations ' , $ this ->translationDir . '/templates ' , $ transPaths , $ codePaths );
265
306
266
307
$ application = new Application ($ kernel );
267
308
$ application ->add ($ command );
@@ -275,8 +316,7 @@ private function getBundle($path)
275
316
$ bundle
276
317
->expects ($ this ->any ())
277
318
->method ('getPath ' )
278
- ->willReturn ($ path )
279
- ;
319
+ ->willReturn ($ path );
280
320
281
321
return $ bundle ;
282
322
}
0 commit comments