|
15 | 15 | use Psr\Log\LoggerInterface;
|
16 | 16 | use Psr\Log\NullLogger;
|
17 | 17 | use Symfony\Component\Config\FileLocator;
|
| 18 | +use Symfony\Component\DependencyInjection\Compiler\AutowireAsDecoratorPass; |
18 | 19 | use Symfony\Component\DependencyInjection\Compiler\AutowirePass;
|
19 | 20 | use Symfony\Component\DependencyInjection\Compiler\AutowireRequiredMethodsPass;
|
20 | 21 | use Symfony\Component\DependencyInjection\Compiler\DecoratorServicePass;
|
@@ -1164,4 +1165,25 @@ public function testAutowireAttribute()
|
1164 | 1165 | $this->assertSame('@bar', $service->escapedRawValue);
|
1165 | 1166 | $this->assertNull($service->invalid);
|
1166 | 1167 | }
|
| 1168 | + |
| 1169 | + public function testAsDecoratorAttribute() |
| 1170 | + { |
| 1171 | + $container = new ContainerBuilder(); |
| 1172 | + |
| 1173 | + $container->register(AsDecoratorFoo::class); |
| 1174 | + $container->register(AsDecoratorBar10::class)->setAutowired(true)->setArgument(0, 'arg1'); |
| 1175 | + $container->register(AsDecoratorBar20::class)->setAutowired(true)->setArgument(0, 'arg1'); |
| 1176 | + $container->register(AsDecoratorBaz::class)->setAutowired(true); |
| 1177 | + |
| 1178 | + (new ResolveClassPass())->process($container); |
| 1179 | + (new AutowireAsDecoratorPass())->process($container); |
| 1180 | + (new DecoratorServicePass())->process($container); |
| 1181 | + (new AutowirePass())->process($container); |
| 1182 | + |
| 1183 | + $this->assertSame(AsDecoratorBar10::class.'.inner', (string) $container->getDefinition(AsDecoratorBar10::class)->getArgument(1)); |
| 1184 | + |
| 1185 | + $this->assertSame(AsDecoratorBar20::class.'.inner', (string) $container->getDefinition(AsDecoratorBar20::class)->getArgument(1)); |
| 1186 | + $this->assertSame(AsDecoratorBaz::class.'.inner', (string) $container->getDefinition(AsDecoratorBaz::class)->getArgument(0)); |
| 1187 | + $this->assertSame(2, $container->getDefinition(AsDecoratorBaz::class)->getArgument(0)->getInvalidBehavior()); |
| 1188 | + } |
1167 | 1189 | }
|
0 commit comments