8000 Add tests · symfony/symfony@ceb615f · GitHub
[go: up one dir, main page]

Skip to content

Commit ceb615f

Browse files
committed
Add tests
1 parent 4eea56e commit ceb615f

File tree

7 files changed

+105
-6
lines changed

7 files changed

+105
-6
lines changed

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

Lines 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

Lines 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

Lines changed: 55 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,11 +12,18 @@
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;
26+
use Symfony\Contracts\Translation\TranslatorInterface;
2027

2128
class TranslationPassTest extends TestCase
2229
{
@@ -54,4 +61,52 @@ public function testValidCollector()
5461
$expected = array('translation.xliff_loader' => new ServiceClosureArgument(new Reference('translation.xliff_loader')));
5562
$this->assertEquals($expected, $container->getDefinition((string) $translator->getArgument(0))->getArgument(0));
5663
}
64+
65+
public function testCommandArguments()
66+
{
67+
$translator = (new Definition(Translator::class))
68+
->setArguments(array(null, null, null, null));
69+
$debugCommand = (new Definition())
70+
->setArguments(array(null, null, null, null, null, array(), array()));
71+
$updateCommand = (new Definition())
72+
->setArguments(array(null, null, null, null, null, null, array(), array()));
73+
$twigTemplateIterator = (new Definition())
74+
->setArguments(array(null, null, array('other/templates' => null)));
75+
76+
$serviceProperties = (new Definition(ServiceProperties::class))
77+
->setProperties(array(new Reference('translator.default')));
78+
$serviceBindings = (new Definition(ServiceBindings::class))
79+
->setBindings(array(new BoundArgument(new Reference('translator.default'))));
80+
$serviceArguments = (new Definition(ServiceArguments::class))
81+
->setArguments(array(new Reference('translator.default')));
82+
$serviceMethodCalls = (new Definition(ServiceMethodCalls::class))
83+
->setMethodCalls(array(array('setTranslator', array(new Reference('translator.default')))));
84+
85+
$container = new ContainerBuilder();
86+
$container->setDefinition('translator.default', $translator);
87+
$container->setDefinition('console.command.translation_debug', $debugCommand);
88+
$container->setDefinition('console.command.translation_update', $updateCommand);
89+
$container->setDefinition('twig.template_iterator', $twigTemplateIterator);
90+
$container->setDefinition('service_p', $serviceProperties);
91+
$container->setDefinition('service_b', $serviceBindings);
92+
$container->setDefinition('service_a', $serviceArguments);
93+
$container->setDefinition('service_m', $serviceMethodCalls);
94+
$container->setParameter('twig.default_path', 'templates');
95+
96+
$pass = new TranslatorPass('translator.default', 'translation.reader');
97+
$pass->process($container);
98+
99+
$expectedPaths = array(
100+
'other/templates',
101+
$container->getReflectionClass(ServiceProperties::class)->getFileName(),
102+
$container->getReflectionClass(ServiceBindings::class)->getFileName(),
103+
$container->getReflectionClass(ServiceArguments::class)->getFileName(),
104+
$container->getReflectionClass(ServiceMethodCalls::class)->getFileName(),
105+
);
106+
107+
$this->assertSame('templates', $debugCommand->getArgument(4));
108+
$this->assertSame('templates', $updateCommand->getArgument(5));
109+
$this->assertSame($expectedPaths, $debugCommand->getArgument(6));
110+
$this->assertSame($expectedPaths, $updateCommand->getArgument(7));
111+
}
57112
}
Lines 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+
}
Lines changed: 12 additions & 0 deletions
Original file line numberDiff l F42D ine 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+
}
Lines 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+
}
Lines 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