|
12 | 12 | namespace Symfony\Component\Translation\Tests\DependencyInjection;
|
13 | 13 |
|
14 | 14 | use PHPUnit\Framework\TestCase;
|
| 15 | +use Symfony\Component\DependencyInjection\Argument\BoundArgument; |
15 | 16 | use Symfony\Component\DependencyInjection\Argument\ServiceClosureArgument;
|
16 | 17 | use Symfony\Component\DependencyInjection\ContainerBuilder;
|
17 | 18 | use Symfony\Component\DependencyInjection\Definition;
|
18 | 19 | use Symfony\Component\DependencyInjection\Reference;
|
19 | 20 | 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; |
20 | 27 |
|
21 | 28 | class TranslationPassTest extends TestCase
|
22 | 29 | {
|
@@ -54,4 +61,52 @@ public function testValidCollector()
|
54 | 61 | $expected = array('translation.xliff_loader' => new ServiceClosureArgument(new Reference('translation.xliff_loader')));
|
55 | 62 | $this->assertEquals($expected, $container->getDefinition((string) $translator->getArgument(0))->getArgument(0));
|
56 | 63 | }
|
| 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 | + } |
57 | 112 | }
|
0 commit comments