Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit 6878c2f

Browse files
committed
Add test for removeNoFillTranslations
1 parent 3ed0b51 commit 6878c2f

File tree

2 files changed

+52
-13
lines changed

2 files changed

+52
-13
lines changed

src/Symfony/Bundle/FrameworkBundle/Command/TranslationUpdateCommand.php

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,6 @@
1919
use Symfony\Component\Console\Input\InputArgument;
2020
use Symfony\Component\Console\Input\InputInterface;
2121
use Symfony\Component\Console\Input\InputOption;
22-
use Symfony\Component\Console\Output\ConsoleOutputInterface;
2322
use Symfony\Component\Console\Output\OutputInterface;
2423
use Symfony\Component\Console\Style\SymfonyStyle;
2524
use Symfony\Component\HttpKernel\KernelInterface;

src/Symfony/Bundle/FrameworkBundle/Tests/Command/TranslationUpdateCommandTest.php

Lines changed: 52 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@
2121
use Symfony\Component\HttpKernel\KernelInterface;
2222
use Symfony\Component\Translation\Extractor\ExtractorInterface;
2323
use Symfony\Component\Translation\MessageCatalogue;
24+
use Symfony\Component\Translation\MessageCatalogueInterface;
2425
use Symfony\Component\Translation\Reader\TranslationReader;
2526
use Symfony\Component\Translation\Translator;
2627
use Symfony\Component\Translation\Writer\TranslationWriter;
@@ -79,7 +80,7 @@ public function testDumpWrongSortAndClean()
7980

8081
public function testDumpMessagesAndCleanInRootDirectory()
8182
{
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']);
8384
$tester->execute(['command' => 'translation:extract', 'locale' => 'en', '--dump-messages' => true, '--clean' => true]);
8485
$this->assertMatchesRegularExpression('/foo/', $tester->getDisplay());
8586
$this->assertMatchesRegularExpression('/1 message was successfully extracted/', $tester->getDisplay());
@@ -140,10 +141,10 @@ public function testWriteMessagesForSpecificDomain()
140141
public function testFilterDuplicateTransPaths()
141142
{
142143
$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',
147148
];
148149

149150
foreach ($transPaths as $transPath) {
@@ -169,20 +170,60 @@ public function testFilterDuplicateTransPaths()
169170
$filteredTransPaths = $method->invoke($command, $transPaths);
170171

171172
$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'),
174175
];
175176

176177
$this->assertEquals($expectedPaths, $filteredTransPaths);
177178
}
178179

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+
179220
protected function setUp(): void
180221
{
181222
$this->fs = new Filesystem();
182223
$this->translationDir = tempnam(sys_get_temp_dir(), 'sf_translation_');
183224
$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');
186227
}
187228

188229
protected function tearDown(): void
@@ -261,7 +302,7 @@ function (MessageCatalogue $catalogue) use ($writerMessages) {
261302
->method('getContainer')
262303
->willReturn($container);
263304

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);
265306

266307
$application = new Application($kernel);
267308
$application->add($command);
@@ -275,8 +316,7 @@ private function getBundle($path)
275316
$bundle
276317
->expects($this->any())
277318
->method('getPath')
278-
->willReturn($path)
279-
;
319+
->willReturn($path);
280320

281321
return $bundle;
282322
}

0 commit comments

Comments
 (0)