|
20 | 20 | use Symfony\Component\DependencyInjection\Compiler\DecoratorServicePass;
|
21 | 21 | use Symfony\Component\DependencyInjection\Compiler\ResolveClassPass;
|
22 | 22 | use Symfony\Component\DependencyInjection\ContainerBuilder;
|
| 23 | +use Symfony\Component\DependencyInjection\ContainerInterface; |
23 | 24 | use Symfony\Component\DependencyInjection\Exception\AutowiringFailedException;
|
24 | 25 | use Symfony\Component\DependencyInjection\Exception\RuntimeException;
|
25 | 26 | use Symfony\Component\DependencyInjection\Loader\XmlFileLoader;
|
|
29 | 30 | use Symfony\Component\DependencyInjection\Tests\Fixtures\includes\FooVariadic;
|
30 | 31 | use Symfony\Component\DependencyInjection\Tests\Fixtures\WithTarget;
|
31 | 32 | use Symfony\Component\DependencyInjection\TypedReference;
|
| 33 | +use Symfony\Component\ExpressionLanguage\Expression; |
32 | 34 | use Symfony\Contracts\Service\Attribute\Required;
|
33 | 35 |
|
34 | 36 | require_once __DIR__.'/../Fixtures/includes/autowiring_classes.php';
|
@@ -1121,4 +1123,37 @@ public function testDecorationWithServiceAndAliasedInterface()
|
1121 | 1123 | static::assertInstanceOf(DecoratedDecorator::class, $container->get(DecoratorInterface::class));
|
1122 | 1124 | static::assertInstanceOf(DecoratedDecorator::class, $container->get(DecoratorImpl::class));
|
1123 | 1125 | }
|
| 1126 | + |
| 1127 | + public function testAutowireAttribute() |
| 1128 | + { |
| 1129 | + $container = new ContainerBuilder(); |
| 1130 | + |
| 1131 | + $container->register(AutowireAttribute::class) |
| 1132 | + ->setAutowired(true) |
| 1133 | + ->setPublic(true) |
| 1134 | + ; |
| 1135 | + |
| 1136 | + $container->register('some.id', \stdClass::class); |
| 1137 | + $container->setParameter('some.parameter', 'foo'); |
| 1138 | + |
| 1139 | + (new ResolveClassPass())->process($container); |
| 1140 | + (new AutowirePass())->process($container); |
| 1141 | + |
| 1142 | + $definition = $container->getDefinition(AutowireAttribute::class); |
| 1143 | + |
| 1144 | + $this->assertCount(4, $definition->getArguments()); |
| 1145 | + $this->assertEquals(new Reference('some.id'), $definition->getArgument(0)); |
| 1146 | + $this->assertEquals(new Expression("parameter('some.parameter')"), $definition->getArgument(1)); |
| 1147 | + $this->assertSame('%some.parameter%/bar', $definition->getArgument(2)); |
| 1148 | + $this->assertEquals(new Reference('invalid.id', ContainerInterface::NULL_ON_INVALID_REFERENCE), $definition->getArgument(3)); |
| 1149 | + |
| 1150 | + $container->compile(); |
| 1151 | + |
| 1152 | + $service = $container->get(AutowireAttribute::class); |
| 1153 | + |
| 1154 | + $this->assertInstanceOf(\stdClass::class, $service->service); |
| 1155 | + $this->assertSame('foo', $service->expression); |
| 1156 | + $this->assertSame('foo/bar', $service->value); |
| 1157 | + $this->assertNull($service->invalid); |
| 1158 | + } |
1124 | 1159 | }
|
0 commit comments