|
11 | 11 |
|
12 | 12 | namespace Symfony\Component\DependencyInjection\Tests\Compiler;
|
13 | 13 |
|
| 14 | +use Symfony\Component\DependencyInjection\Alias; |
| 15 | +use Symfony\Component\DependencyInjection\Definition; |
14 | 16 | use Symfony\Component\DependencyInjection\Reference;
|
15 | 17 | use Symfony\Component\DependencyInjection\Compiler\ResolveReferencesToAliasesPass;
|
16 | 18 | use Symfony\Component\DependencyInjection\ContainerBuilder;
|
@@ -59,6 +61,45 @@ public function testAliasCircularReference()
|
59 | 61 | $this->process($container);
|
60 | 62 | }
|
61 | 63 |
|
| 64 | + public function testResolveFactory() |
| 65 | + { |
| 66 | + $container = new ContainerBuilder(); |
| 67 | + $container->register('factory', 'Factory'); |
| 68 | + $container->setAlias('factory_alias', new Alias('factory')); |
| 69 | + $foo = new Definition(); |
| 70 | + $foo->setFactory(array(new Reference('factory_alias'), 'createFoo')); |
| 71 | + $container->setDefinition('foo', $foo); |
| 72 | + $bar = new Definition(); |
| 73 | + $bar->setFactory(array('Factory', 'createFoo')); |
| 74 | + $container->setDefinition('bar', $bar); |
| 75 | + |
| 76 | + $this->process($container); |
| 77 | + |
| 78 | + $resolvedFooFactory = $container->getDefinition('foo')->getFactory(); |
| 79 | + $resolvedBarFactory = $container->getDefinition('bar')->getFactory(); |
| 80 | + |
| 81 | + $this->assertSame('factory', (string) $resolvedFooFactory[0]); |
| 82 | + $this->assertSame('Factory', (string) $resolvedBarFactory[0]); |
| 83 | + } |
| 84 | + |
| 85 | + /** |
| 86 | + * @group legacy |
| 87 | + */ |
| 88 | + public function testResolveFactoryService() |
| 89 | + { |
| 90 | + $container = new ContainerBuilder(); |
| 91 | + $container->register('factory', 'Factory'); |
| 92 | + $container->setAlias('factory_alias', new Alias('factory')); |
| 93 | + $foo = new Definition(); |
| 94 | + $foo->setFactoryService('factory_alias'); |
| 95 | + $foo->setFactoryMethod('createFoo'); |
| 96 | + $container->setDefinition('foo', $foo); |
| 97 | + |
| 98 | + $this->process($container); |
| 99 | + |
| 100 | + $this->assertSame('factory', $foo->getFactoryService()); |
| 101 | + } |
| 102 | + |
62 | 103 | protected function process(ContainerBuilder $container)
|
63 | 104 | {
|
64 | 105 | $pass = new ResolveReferencesToAliasesPass();
|
|
0 commit comments