|
14 | 14 | use PHPUnit\Framework\TestCase;
|
15 | 15 | use Symfony\Component\Config\FileLocator;
|
16 | 16 | use Symfony\Component\DependencyInjection\Alias;
|
| 17 | +use Symfony\Component\DependencyInjection\Argument\TaggedIteratorArgument; |
17 | 18 | use Symfony\Component\DependencyInjection\ContainerBuilder;
|
18 | 19 | use Symfony\Component\DependencyInjection\Loader\YamlFileLoader;
|
19 | 20 | use Symfony\Component\DependencyInjection\Reference;
|
20 | 21 | use Symfony\Component\DependencyInjection\ServiceSubscriberInterface;
|
| 22 | +use Symfony\Component\DependencyInjection\Tests\Fixtures\BarTagClass; |
| 23 | +use Symfony\Component\DependencyInjection\Tests\Fixtures\FooBarTaggedClass; |
| 24 | +use Symfony\Component\DependencyInjection\Tests\Fixtures\FooTagClass; |
21 | 25 |
|
22 | 26 | /**
|
23 | 27 | * This class tests the integration of the different compiler passes.
|
@@ -234,6 +238,54 @@ public function getYamlCompileTests()
|
234 | 238 | $container,
|
235 | 239 | ];
|
236 | 240 | }
|
| 241 | + |
| 242 | + public function testTaggedServiceWithIndexAttribute() |
| 243 | + { |
| 244 | + $container = new ContainerBuilder(); |
| 245 | + $container->register(BarTagClass::class, BarTagClass::class) |
| 246 | + ->setPublic(true) |
| 247 | + ->addTag('foo_bar', ['foo' => 'bar']) |
| 248 | + ; |
| 249 | + $container->register(FooTagClass::class, FooTagClass::class) |
| 250 | + ->setPublic(true) |
| 251 | + ->addTag('foo_bar') |
| 252 | + ; |
| 253 | + $container->register(FooBarTaggedClass::class, FooBarTaggedClass::class) |
| 254 | + ->addArgument(new TaggedIteratorArgument('foo_bar', 'foo')) |
| 255 | + ->setPublic(true) |
| 256 | + ; |
| 257 | + |
| 258 | + $container->compile(); |
| 259 | + |
| 260 | + $s = $container->get(FooBarTaggedClass::class); |
| 261 | + |
| 262 | + $param = iterator_to_array($s->getParam()->getIterator()); |
| 263 | + $this->assertSame(['bar' => $container->get(BarTagClass::class), 'foo_tag_class' => $container->get(FooTagClass::class)], $param); |
| 264 | + } |
| 265 | + |
| 266 | + public function testTaggedServiceWithIndexAttributeAndDefaultMethod() |
| 267 | + { |
| 268 | + $container = new ContainerBuilder(); |
| 269 | + $container->register(BarTagClass::class, BarTagClass::class) |
| 270 | + ->setPublic(true) |
| 271 | + ->addTag('foo_bar') |
| 272 | + ; |
| 273 | + $container->register(FooTagClass::class, FooTagClass::class) |
| 274 | + ->setPublic(true) |
| 275 | + ->addTag('foo_bar', ['foo' => 'foo']) |
| 276 | + ; |
| 277 | + $container->register(FooBarTaggedClass::class, FooBarTaggedClass::class) |
| 278 | + ->addArgument(new TaggedIteratorArgument('foo_bar', 'foo', 'getFooBar')) |
| 279 | + ->setPublic(true) |
| 280 | + ; |
| 281 | + |
| 282 | + $container->compile(); |
| 283 | + |
| 284 | + $s = $container->get(FooBarTaggedClass::class); |
| 285 | + |
| 286 | + $param = iterator_to_array($s->getParam()->getIterator()); |
| 287 | + $this->assertSame(['bar_tab_class_with_defaultmethod' => $container->get(BarTagClass::class), 'foo' => $container->get(FooTagClass::class)], $param); |
| 288 | + } |
237 | 289 | }
|
238 | 290 |
|
239 | 291 | class ServiceSubscriberStub implements ServiceSubscriberInterface
|
|
0 commit comments