Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings

Commit 46fc19b

Browse filesBrowse files
committed
Add tests
1 parent 4eea56e commit 46fc19b
Copy full SHA for 46fc19b

File tree

7 files changed

+104
-6
lines changed
Filter options

7 files changed

+104
-6
lines changed

‎src/Symfony/Bundle/FrameworkBundle/Tests/Command/TranslationDebugCommandTest.php

Copy file name to clipboardExpand all lines: src/Symfony/Bundle/FrameworkBundle/Tests/Command/TranslationDebugCommandTest.php
+3-3Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -90,7 +90,7 @@ public function testDebugDefaultRootDirectory()
9090
$this->fs->mkdir($this->translationDir.'/translations');
9191
$this->fs->mkdir($this->translationDir.'/templates');
9292

93-
$tester = $this->createCommandTester(array('foo' => 'foo'), array('bar' => 'bar'));
93+
$tester = $this->createCommandTester(array('foo' => 'foo'), array('bar' => 'bar'), null, array($this->translationDir.'/trans'), array($this->translationDir.'/views'));
9494
$tester->execute(array('locale' => 'en'));
9595

9696
$this->assertRegExp('/missing/', $tester->getDisplay());
@@ -145,7 +145,7 @@ protected function tearDown()
145145
/**
146146
* @return CommandTester
147147
*/
148-
private function createCommandTester($extractedMessages = array(), $loadedMessages = array(), $kernel = null)
148+
private function createCommandTester($extractedMessages = array(), $loadedMessages = array(), $kernel = null, array $transPaths = array(), array $viewsPaths = array())
149149
{
150150
$translator = $this->getMockBuilder('Symfony\Component\Translation\Translator')
151151
->disableOriginalConstructor()
@@ -207,7 +207,7 @@ private function createCommandTester($extractedMessages = array(), $loadedMessag
207207
->method('getContainer')
208208
->will($this->returnValue($container));
209209

210-
$command = new TranslationDebugCommand($translator, $loader, $extractor, $this->translationDir.'/translations', $this->translationDir.'/templates');
210+
$command = new TranslationDebugCommand($translator, $loader, $extractor, $this->translationDir.'/translations', $this->translationDir.'/templates', $transPaths, $viewsPaths);
211211

212212
$application = new Application($kernel);
213213
$application->add($command);

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

Copy file name to clipboardExpand all lines: src/Symfony/Bundle/FrameworkBundle/Tests/Command/TranslationUpdateCommandTest.php
+3-3Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,7 @@ public function testDumpMessagesAndCleanInRootDirectory()
3939
$this->fs->mkdir($this->translationDir.'/translations');
4040
$this->fs->mkdir($this->translationDir.'/templates');
4141

42-
$tester = $this->createCommandTester(array('messages' => array('foo' => 'foo')));
42+
$tester = $this->createCommandTester(array('messages' => array('foo' => 'foo')), array(), null, array($this->translationDir.'/trans'), array($this->translationDir.'/views'));
4343
$tester->execute(array('command' => 'translation:update', 'locale' => 'en', '--dump-messages' => true, '--clean' => true));
4444
$this->assertRegExp('/foo/', $tester->getDisplay());
4545
$this->assertRegExp('/1 message was successfully extracted/', $tester->getDisplay());
@@ -121,7 +121,7 @@ protected function tearDown()
121121
/**
122122
* @return CommandTester
123123
*/
124-
private function createCommandTester($extractedMessages = array(), $loadedMessages = array(), HttpKernel\KernelInterface $kernel = null)
124+
private function createCommandTester($extractedMessages = array(), $loadedMessages = array(), HttpKernel\KernelInterface $kernel = null, array $transPaths = array(), array $viewsPaths = array())
125125
{
126126
$translator = $this->getMockBuilder('Symfony\Component\Translation\Translator')
127127
->disableOriginalConstructor()
@@ -197,7 +197,7 @@ private function createCommandTester($extractedMessages = array(), $loadedMessag
197197
->method('getContainer')
198198
->will($this->returnValue($container));
199199

200-
$command = new TranslationUpdateCommand($writer, $loader, $extractor, 'en', $this->translationDir.'/translations', $this->translationDir.'/templates');
200+
$command = new TranslationUpdateCommand($writer, $loader, $extractor, 'en', $this->translationDir.'/translations', $this->translationDir.'/templates', $transPaths, $viewsPaths);
201201

202202
$application = new Application($kernel);
203203
$application->add($command);

‎src/Symfony/Component/Translation/Tests/DependencyInjection/TranslationPassTest.php

Copy file name to clipboardExpand all lines: src/Symfony/Component/Translation/Tests/DependencyInjection/TranslationPassTest.php
+54Lines changed: 54 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,11 +12,17 @@
1212
namespace Symfony\Component\Translation\Tests\DependencyInjection;
1313

1414
use PHPUnit\Framework\TestCase;
15+
use Symfony\Component\DependencyInjection\Argument\BoundArgument;
1516
use Symfony\Component\DependencyInjection\Argument\ServiceClosureArgument;
1617
use Symfony\Component\DependencyInjection\ContainerBuilder;
1718
use Symfony\Component\DependencyInjection\Definition;
1819
use Symfony\Component\DependencyInjection\Reference;
1920
use Symfony\Component\Translation\DependencyInjection\TranslatorPass;
21+
use Symfony\Component\Translation\Tests\DependencyInjection\fixtures\ServiceArguments;
22+
use Symfony\Component\Translation\Tests\DependencyInjection\fixtures\ServiceBindings;
23+
use Symfony\Component\Translation\Tests\DependencyInjection\fixtures\ServiceMethodCalls;
24+
use Symfony\Component\Translation\Tests\DependencyInjection\fixtures\ServiceProperties;
25+
use Symfony\Component\Translation\Translator;
2026

2127
class TranslationPassTest extends TestCase
2228
{
@@ -54,4 +60,52 @@ public function testValidCollector()
5460
$expected = array('translation.xliff_loader' => new ServiceClosureArgument(new Reference('translation.xliff_loader')));
5561
$this->assertEquals($expected, $container->getDefinition((string) $translator->getArgument(0))->getArgument(0));
5662
}
63+
64+
public function testCommandArguments()
65+
{
66+
$translator = (new Definition(Translator::class))
67+
->setArguments(array(null, null, null, null));
68+
$debugCommand = (new Definition())
69+
->setArguments(array(null, null, null, null, null, array(), array()));
70+
$updateCommand = (new Definition())
71+
->setArguments(array(null, null, null, null, null, null, array(), array()));
72+
$twigTemplateIterator = (new Definition())
73+
->setArguments(array(null, null, array('other/templates' => null)));
74+
75+
$serviceProperties = (new Definition(ServiceProperties::class))
76+
->setProperties(array(new Reference('translator.default')));
77+
$serviceBindings = (new Definition(ServiceBindings::class))
78+
->setBindings(array(new BoundArgument(new Reference('translator.default'))));
79+
$serviceArguments = (new Definition(ServiceArguments::class))
80+
->setArguments(array(new Reference('translator.default')));
81+
$serviceMethodCalls = (new Definition(ServiceMethodCalls::class))
82+
->setMethodCalls(array(array('setTranslator', array(new Reference('translator.default')))));
83+
84+
$container = new ContainerBuilder();
85+
$container->setDefinition('translator.default', $translator);
86+
$container->setDefinition('console.command.translation_debug', $debugCommand);
87+
$container->setDefinition('console.command.translation_update', $updateCommand);
88+
$container->setDefinition('twig.template_iterator', $twigTemplateIterator);
89+
$container->setDefinition('service_p', $serviceProperties);
90+
$container->setDefinition('service_b', $serviceBindings);
91+
$container->setDefinition('service_a', $serviceArguments);
92+
$container->setDefinition('service_m', $serviceMethodCalls);
93+
$container->setParameter('twig.default_path', 'templates');
94+
95+
$pass = new TranslatorPass('translator.default', 'translation.reader');
96+
$pass->process($container);
97+
98+
$expectedPaths = array(
99+
'other/templates',
100+
$container->getReflectionClass(ServiceProperties::class)->getFileName(),
101+
$container->getReflectionClass(ServiceBindings::class)->getFileName(),
102+
$container->getReflectionClass(ServiceArguments::class)->getFileName(),
103+
$container->getReflectionClass(ServiceMethodCalls::class)->getFileName(),
104+
);
105+
106+
$this->assertSame('templates', $debugCommand->getArgument(4));
107+
$this->assertSame('templates', $updateCommand->getArgument(5));
108+
$this->assertSame($expectedPaths, $debugCommand->getArgument(6));
109+
$this->assertSame($expectedPaths, $updateCommand->getArgument(7));
110+
}
57111
}
+12Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
<?php
2+
3+
namespace Symfony\Component\Translation\Tests\DependencyInjection\fixtures;
4+
5+
use Symfony\Contracts\Translation\TranslatorInterface;
6+
7+
class ServiceArguments
8+
{
9+
public function __construct(TranslatorInterface $translator)
10+
{
11+
}
12+
}
+12Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
<?php
2+
3+
namespace Symfony\Component\Translation\Tests\DependencyInjection\fixtures;
4+
5+
use Symfony\Contracts\Translation\TranslatorInterface;
6+
7+
class ServiceBindings
8+
{
9+
public function bindings(TranslatorInterface $translator)
10+
{
11+
}
12+
}
+12Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
<?php
2+
3+
namespace Symfony\Component\Translation\Tests\DependencyInjection\fixtures;
4+
5+
use Symfony\Contracts\Translation\TranslatorInterface;
6+
7+
class ServiceMethodCalls
8+
{
9+
public function setTranslator(TranslatorInterface $translator)
10+
{
11+
}
12+
}
+8Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
<?php
2+
3+
namespace Symfony\Component\Translation\Tests\DependencyInjection\fixtures;
4+
5+
class ServiceProperties
6+
{
7+
public $translator;
8+
}

0 commit comments

Comments
0 (0)
Morty Proxy This is a proxified and sanitized view of the page, visit original site.