|
32 | 32 | use Symfony\Component\DependencyInjection\Tests\Fixtures\TestServiceSubscriber;
|
33 | 33 | use Symfony\Component\DependencyInjection\Tests\Fixtures\TestServiceSubscriberChild;
|
34 | 34 | use Symfony\Component\DependencyInjection\Tests\Fixtures\TestServiceSubscriberParent;
|
| 35 | +use Symfony\Component\DependencyInjection\Tests\Fixtures\TestServiceSubscriberUnion; |
35 | 36 | use Symfony\Component\DependencyInjection\TypedReference;
|
36 | 37 | use Symfony\Contracts\Service\Attribute\SubscribedService;
|
37 | 38 | use Symfony\Contracts\Service\ServiceSubscriberInterface;
|
@@ -129,6 +130,36 @@ public function testWithAttributes()
|
129 | 130 | $this->assertEquals($expected, $container->getDefinition((string) $locator->getFactory()[0])->getArgument(0));
|
130 | 131 | }
|
131 | 132 |
|
| 133 | + /** |
| 134 | + * @requires PHP 8 |
| 135 | + */ |
| 136 | + public function testUnionServices() |
| 137 | + { |
| 138 | + $container = new ContainerBuilder(); |
| 139 | + |
| 140 | + $container->register('foo', TestServiceSubscriberUnion::class) |
| 141 | + ->addArgument(new Reference(PsrContainerInterface::class)) |
| 142 | + ->addTag('container.service_subscriber') |
| 143 | + ; |
| 144 | + |
| 145 | + (new RegisterServiceSubscribersPass())->process($container); |
| 146 | + (new ResolveServiceSubscribersPass())->process($container); |
| 147 | + |
| 148 | + $foo = $container->getDefinition('foo'); |
| 149 | + $locator = $container->getDefinition((string) $foo->getArgument(0)); |
| 150 | + |
| 151 | + $this->assertFalse($locator->isPublic()); |
| 152 | + $this->assertSame(ServiceLocator::class, $locator->getClass()); |
| 153 | + |
| 154 | + $expected = [ |
| 155 | + TestDefinition1::class.'|'.TestDefinition2::class => new ServiceClosureArgument(new TypedReference(TestDefinition1::class.'|'.TestDefinition2::class, TestDefinition1::class.'|'.TestDefinition2::class)), |
| 156 | + 'bar' => new ServiceClosureArgument(new TypedReference(TestDefinition1::class.'|'.TestDefinition2::class, TestDefinition1::class.'|'.TestDefinition2::class, ContainerInterface::EXCEPTION_ON_INVALID_REFERENCE, 'bar')), |
| 157 | + 'baz' => new ServiceClosureArgument(new TypedReference(TestDefinition1::class.'|'.TestDefinition2::class, TestDefinition1::class.'|'.TestDefinition2::class, ContainerInterface::IGNORE_ON_INVALID_REFERENCE, 'baz')), |
| 158 | + ]; |
| 159 | + |
| 160 | + $this->assertEquals($expected, $container->getDefinition((string) $locator->getFactory()[0])->getArgument(0)); |
| 161 | + } |
| 162 | + |
132 | 163 | public function testExtraServiceSubscriber()
|
133 | 164 | {
|
134 | 165 | $this->expectException(InvalidArgumentException::class);
|
|
0 commit comments