|
16 | 16 | use Symfony\Component\DependencyInjection\Argument\ServiceClosureArgument;
|
17 | 17 | use Symfony\Component\DependencyInjection\Compiler\AutowirePass;
|
18 | 18 | use Symfony\Component\DependencyInjection\Compiler\RegisterServiceSubscribersPass;
|
| 19 | +use Symfony\Component\DependencyInjection\Compiler\ResolveBindingsPass; |
19 | 20 | use Symfony\Component\DependencyInjection\Compiler\ResolveServiceSubscribersPass;
|
20 | 21 | use Symfony\Component\DependencyInjection\ContainerBuilder;
|
21 | 22 | use Symfony\Component\DependencyInjection\ContainerInterface;
|
@@ -235,4 +236,33 @@ public static function getSubscribedServices()
|
235 | 236 | ];
|
236 | 237 | $this->assertEquals($expected, $container->getDefinition((string) $locator->getFactory()[0])->getArgument(0));
|
237 | 238 | }
|
| 239 | + |
| 240 | + public function testBinding() |
| 241 | + { |
| 242 | + $container = new ContainerBuilder(); |
| 243 | + |
| 244 | + $container->register('foo', TestServiceSubscriber::class) |
| 245 | + ->addMethodCall('setServiceProvider') |
| 246 | + ->addTag('container.service_subscriber') |
| 247 | + ; |
| 248 | + |
| 249 | + (new RegisterServiceSubscribersPass())->process($container); |
| 250 | + (new ResolveBindingsPass())->process($container); |
| 251 | + |
| 252 | + $foo = $container->getDefinition('foo'); |
| 253 | + $locator = $container->getDefinition((string) $foo->getMethodCalls()[0][1][0]); |
| 254 | + |
| 255 | + $this->assertFalse($locator->isPublic()); |
| 256 | + $this->assertSame(ServiceLocator::class, $locator->getClass()); |
| 257 | + |
| 258 | + $expected = [ |
| 259 | + TestServiceSubscriber::class => new ServiceClosureArgument(new TypedReference(TestServiceSubscriber::class, TestServiceSubscriber::class)), |
| 260 | + CustomDefinition::class => new ServiceClosureArgument(new TypedReference(CustomDefinition::class, CustomDefinition::class, ContainerInterface::IGNORE_ON_INVALID_REFERENCE)), |
| 261 | + 'bar' => new ServiceClosureArgument(new TypedReference(CustomDefinition::class, CustomDefinition::class, ContainerInterface::EXCEPTION_ON_INVALID_REFERENCE, 'bar')), |
| 262 | + 'baz' => new ServiceClosureArgument(new TypedReference(CustomDefinition::class, CustomDefinition::class, ContainerInterface::IGNORE_ON_INVALID_REFERENCE, 'baz')), |
| 263 | + ]; |
| 264 | + |
| 265 | + $this->assertEquals($expected, $container->getDefinition((string) $locator->getFactory()[0])->getArgument(0)); |
| 266 | + } |
| 267 | + |
238 | 268 | }
|
0 commit comments