1 | 1 |
deleted file mode 100644 |
... | ... |
@@ -1,89 +0,0 @@ |
1 |
-<?php |
|
2 |
- |
|
3 |
-/* |
|
4 |
- * This file is part of the Symfony package. |
|
5 |
- * |
|
6 |
- * (c) Fabien Potencier <fabien@symfony.com> |
|
7 |
- * |
|
8 |
- * For the full copyright and license information, please view the LICENSE |
|
9 |
- * file that was distributed with this source code. |
|
10 |
- */ |
|
11 |
- |
|
12 |
-namespace Symfony\Component\Translation\Tests\DependencyInjection; |
|
13 |
- |
|
14 |
-use PHPUnit\Framework\TestCase; |
|
15 |
-use Symfony\Component\DependencyInjection\Argument\ServiceClosureArgument; |
|
16 |
-use Symfony\Component\DependencyInjection\ContainerBuilder; |
|
17 |
-use Symfony\Component\DependencyInjection\Definition; |
|
18 |
-use Symfony\Component\DependencyInjection\Reference; |
|
19 |
-use Symfony\Component\DependencyInjection\ServiceLocator; |
|
20 |
-use Symfony\Component\Translation\DependencyInjection\TranslatorPathsPass; |
|
21 |
-use Symfony\Component\Translation\Tests\DependencyInjection\fixtures\ControllerArguments; |
|
22 |
-use Symfony\Component\Translation\Tests\DependencyInjection\fixtures\ServiceArguments; |
|
23 |
-use Symfony\Component\Translation\Tests\DependencyInjection\fixtures\ServiceMethodCalls; |
|
24 |
-use Symfony\Component\Translation\Tests\DependencyInjection\fixtures\ServiceProperties; |
|
25 |
-use Symfony\Component\Translation\Tests\DependencyInjection\fixtures\ServiceSubscriber; |
|
26 |
- |
|
27 |
-class TranslationPathsPassTest extends TestCase |
|
28 |
-{ |
|
29 |
- public function testProcess() |
|
30 |
- { |
|
31 |
- $container = new ContainerBuilder(); |
|
32 |
- $container->register('translator'); |
|
33 |
- $debugCommand = $container->register('console.command.translation_debug') |
|
34 |
- ->setArguments([null, null, null, null, null, [], []]) |
|
35 |
- ; |
|
36 |
- $updateCommand = $container->register('console.command.translation_update') |
|
37 |
- ->setArguments([null, null, null, null, null, null, [], []]) |
|
38 |
- ; |
|
39 |
- $container->register(ControllerArguments::class, ControllerArguments::class) |
|
40 |
- ->setTags(['controller.service_arguments']) |
|
41 |
- ; |
|
42 |
- $container->register(ServiceArguments::class, ServiceArguments::class) |
|
43 |
- ->setArguments([new Reference('translator')]) |
|
44 |
- ; |
|
45 |
- $container->register(ServiceProperties::class, ServiceProperties::class) |
|
46 |
- ->setProperties([new Reference('translator')]) |
|
47 |
- ; |
|
48 |
- $container->register(ServiceMethodCalls::class, ServiceMethodCalls::class) |
|
49 |
- ->setMethodCalls([['setTranslator', [new Reference('translator')]]]) |
|
50 |
- ; |
|
51 |
- $container->register('service_rc') |
|
52 |
- ->setArguments([new Definition(), new Reference(ServiceMethodCalls::class)]) |
|
53 |
- ; |
|
54 |
- $serviceLocator1 = $container->register('.service_locator.foo', ServiceLocator::class) |
|
55 |
- ->setArguments([new ServiceClosureArgument(new Reference('translator'))]) |
|
56 |
- ; |
|
57 |
- $serviceLocator2 = (new Definition(ServiceLocator::class)) |
|
58 |
- ->setArguments([ServiceSubscriber::class, new Reference('service_container')]) |
|
59 |
- ->setFactory([$serviceLocator1, 'withContext']) |
|
60 |
- ; |
|
61 |
- $container->register('service_subscriber', ServiceSubscriber::class) |
|
62 |
- ->setArguments([$serviceLocator2]) |
|
63 |
- ; |
|
64 |
- $container->register('.service_locator.bar', ServiceLocator::class) |
|
65 |
- ->setArguments([[ |
|
66 |
- ControllerArguments::class.'::index' => new ServiceClosureArgument(new Reference('.service_locator.foo')), |
|
67 |
- ControllerArguments::class.'::__invoke' => new ServiceClosureArgument(new Reference('.service_locator.foo')), |
|
68 |
- ControllerArguments::class => new ServiceClosureArgument(new Reference('.service_locator.foo')), |
|
69 |
- ]]) |
|
70 |
- ; |
|
71 |
- $container->register('argument_resolver.service') |
|
72 |
- ->setArguments([new Reference('.service_locator.bar')]) |
|
73 |
- ; |
|
74 |
- |
|
75 |
- $pass = new TranslatorPathsPass('translator', 'console.command.translation_debug', 'console.command.translation_update', 'argument_resolver.service'); |
|
76 |
- $pass->process($container); |
|
77 |
- |
|
78 |
- $expectedPaths = [ |
|
79 |
- $container->getReflectionClass(ServiceArguments::class)->getFileName(), |
|
80 |
- $container->getReflectionClass(ServiceProperties::class)->getFileName(), |
|
81 |
- $container->getReflectionClass(ServiceMethodCalls::class)->getFileName(), |
|
82 |
- $container->getReflectionClass(ControllerArguments::class)->getFileName(), |
|
83 |
- $container->getReflectionClass(ServiceSubscriber::class)->getFileName(), |
|
84 |
- ]; |
|
85 |
- |
|
86 |
- $this->assertSame($expectedPaths, $debugCommand->getArgument(6)); |
|
87 |
- $this->assertSame($expectedPaths, $updateCommand->getArgument(7)); |
|
88 |
- } |
|
89 |
-} |
1 | 1 |
new file mode 100644 |
... | ... |
@@ -0,0 +1,89 @@ |
1 |
+<?php |
|
2 |
+ |
|
3 |
+/* |
|
4 |
+ * This file is part of the Symfony package. |
|
5 |
+ * |
|
6 |
+ * (c) Fabien Potencier <fabien@symfony.com> |
|
7 |
+ * |
|
8 |
+ * For the full copyright and license information, please view the LICENSE |
|
9 |
+ * file that was distributed with this source code. |
|
10 |
+ */ |
|
11 |
+ |
|
12 |
+namespace Symfony\Component\Translation\Tests\DependencyInjection; |
|
13 |
+ |
|
14 |
+use PHPUnit\Framework\TestCase; |
|
15 |
+use Symfony\Component\DependencyInjection\Argument\ServiceClosureArgument; |
|
16 |
+use Symfony\Component\DependencyInjection\ContainerBuilder; |
|
17 |
+use Symfony\Component\DependencyInjection\Definition; |
|
18 |
+use Symfony\Component\DependencyInjection\Reference; |
|
19 |
+use Symfony\Component\DependencyInjection\ServiceLocator; |
|
20 |
+use Symfony\Component\Translation\DependencyInjection\TranslatorPathsPass; |
|
21 |
+use Symfony\Component\Translation\Tests\DependencyInjection\fixtures\ControllerArguments; |
|
22 |
+use Symfony\Component\Translation\Tests\DependencyInjection\fixtures\ServiceArguments; |
|
23 |
+use Symfony\Component\Translation\Tests\DependencyInjection\fixtures\ServiceMethodCalls; |
|
24 |
+use Symfony\Component\Translation\Tests\DependencyInjection\fixtures\ServiceProperties; |
|
25 |
+use Symfony\Component\Translation\Tests\DependencyInjection\fixtures\ServiceSubscriber; |
|
26 |
+ |
|
27 |
+class TranslationPathsPassTest extends TestCase |
|
28 |
+{ |
|
29 |
+ public function testProcess() |
|
30 |
+ { |
|
31 |
+ $container = new ContainerBuilder(); |
|
32 |
+ $container->register('translator'); |
|
33 |
+ $debugCommand = $container->register('console.command.translation_debug') |
|
34 |
+ ->setArguments([null, null, null, null, null, [], []]) |
|
35 |
+ ; |
|
36 |
+ $updateCommand = $container->register('console.command.translation_update') |
|
37 |
+ ->setArguments([null, null, null, null, null, null, [], []]) |
|
38 |
+ ; |
|
39 |
+ $container->register(ControllerArguments::class, ControllerArguments::class) |
|
40 |
+ ->setTags(['controller.service_arguments']) |
|
41 |
+ ; |
|
42 |
+ $container->register(ServiceArguments::class, ServiceArguments::class) |
|
43 |
+ ->setArguments([new Reference('translator')]) |
|
44 |
+ ; |
|
45 |
+ $container->register(ServiceProperties::class, ServiceProperties::class) |
|
46 |
+ ->setProperties([new Reference('translator')]) |
|
47 |
+ ; |
|
48 |
+ $container->register(ServiceMethodCalls::class, ServiceMethodCalls::class) |
|
49 |
+ ->setMethodCalls([['setTranslator', [new Reference('translator')]]]) |
|
50 |
+ ; |
|
51 |
+ $container->register('service_rc') |
|
52 |
+ ->setArguments([new Definition(), new Reference(ServiceMethodCalls::class)]) |
|
53 |
+ ; |
|
54 |
+ $serviceLocator1 = $container->register('.service_locator.foo', ServiceLocator::class) |
|
55 |
+ ->setArguments([new ServiceClosureArgument(new Reference('translator'))]) |
|
56 |
+ ; |
|
57 |
+ $serviceLocator2 = (new Definition(ServiceLocator::class)) |
|
58 |
+ ->setArguments([ServiceSubscriber::class, new Reference('service_container')]) |
|
59 |
+ ->setFactory([$serviceLocator1, 'withContext']) |
|
60 |
+ ; |
|
61 |
+ $container->register('service_subscriber', ServiceSubscriber::class) |
|
62 |
+ ->setArguments([$serviceLocator2]) |
|
63 |
+ ; |
|
64 |
+ $container->register('.service_locator.bar', ServiceLocator::class) |
|
65 |
+ ->setArguments([[ |
|
66 |
+ ControllerArguments::class.'::index' => new ServiceClosureArgument(new Reference('.service_locator.foo')), |
|
67 |
+ ControllerArguments::class.'::__invoke' => new ServiceClosureArgument(new Reference('.service_locator.foo')), |
|
68 |
+ ControllerArguments::class => new ServiceClosureArgument(new Reference('.service_locator.foo')), |
|
69 |
+ ]]) |
|
70 |
+ ; |
|
71 |
+ $container->register('argument_resolver.service') |
|
72 |
+ ->setArguments([new Reference('.service_locator.bar')]) |
|
73 |
+ ; |
|
74 |
+ |
|
75 |
+ $pass = new TranslatorPathsPass('translator', 'console.command.translation_debug', 'console.command.translation_update', 'argument_resolver.service'); |
|
76 |
+ $pass->process($container); |
|
77 |
+ |
|
78 |
+ $expectedPaths = [ |
|
79 |
+ $container->getReflectionClass(ServiceArguments::class)->getFileName(), |
|
80 |
+ $container->getReflectionClass(ServiceProperties::class)->getFileName(), |
|
81 |
+ $container->getReflectionClass(ServiceMethodCalls::class)->getFileName(), |
|
82 |
+ $container->getReflectionClass(ControllerArguments::class)->getFileName(), |
|
83 |
+ $container->getReflectionClass(ServiceSubscriber::class)->getFileName(), |
|
84 |
+ ]; |
|
85 |
+ |
|
86 |
+ $this->assertSame($expectedPaths, $debugCommand->getArgument(6)); |
|
87 |
+ $this->assertSame($expectedPaths, $updateCommand->getArgument(7)); |
|
88 |
+ } |
|
89 |
+} |