|
24 | 24 | use Symfony\Component\DependencyInjection\Tests\Fixtures\BarTagClass;
|
25 | 25 | use Symfony\Component\DependencyInjection\Tests\Fixtures\FooBarTaggedClass;
|
26 | 26 | use Symfony\Component\DependencyInjection\Tests\Fixtures\FooTagClass;
|
| 27 | +use Symfony\Contracts\Service\ServiceProviderInterface; |
27 | 28 |
|
28 | 29 | /**
|
29 | 30 | * This class tests the integration of the different compiler passes.
|
@@ -145,16 +146,24 @@ public function testCanDecorateServiceSubscriber()
|
145 | 146 | public function testCanDecorateServiceLocator()
|
146 | 147 | {
|
147 | 148 | $container = new ContainerBuilder();
|
| 149 | + |
| 150 | + $container->register('foo', 'stdClass')->setPublic(true); |
| 151 | + |
148 | 152 | $container->register(ServiceLocator::class)
|
149 | 153 | ->addTag('container.service_locator')
|
| 154 | + ->setArguments([[new Reference('foo')]]) |
150 | 155 | ;
|
151 | 156 |
|
152 | 157 | $container->register(DecoratedServiceLocator::class)
|
153 |
| - ->setDecoratedService(ServiceLocator::class); |
| 158 | + ->setDecoratedService(ServiceLocator::class) |
| 159 | + ->setPublic(true) |
| 160 | + ->setArguments([new Reference(DecoratedServiceLocator::class.'.inner')]) |
| 161 | + ; |
154 | 162 |
|
155 | 163 | $container->compile();
|
156 | 164 |
|
157 | 165 | $this->assertInstanceOf(DecoratedServiceLocator::class, $container->get(DecoratedServiceLocator::class));
|
| 166 | + $this->assertSame($container->get('foo'), $container->get(DecoratedServiceLocator::class)->get('foo')); |
158 | 167 | }
|
159 | 168 |
|
160 | 169 | /**
|
@@ -431,8 +440,32 @@ class DecoratedServiceSubscriber
|
431 | 440 | {
|
432 | 441 | }
|
433 | 442 |
|
434 |
| -class DecoratedServiceLocator |
| 443 | +class DecoratedServiceLocator implements ServiceProviderInterface |
435 | 444 | {
|
| 445 | + /** |
| 446 | + * @var ServiceLocator |
| 447 | + */ |
| 448 | + private $locator; |
| 449 | + |
| 450 | + public function __construct(ServiceLocator $locator) |
| 451 | + { |
| 452 | + $this->locator = $locator; |
| 453 | + } |
| 454 | + |
| 455 | + public function get($id) |
| 456 | + { |
| 457 | + return $this->locator->get($id); |
| 458 | + } |
| 459 | + |
| 460 | + public function has($id): bool |
| 461 | + { |
| 462 | + return $this->locator->has($id); |
| 463 | + } |
| 464 | + |
| 465 | + public function getProvidedServices(): array |
| 466 | + { |
| 467 | + return $this->locator->getProvidedServices(); |
| 468 | + } |
436 | 469 | }
|
437 | 470 |
|
438 | 471 | class IntegrationTestStub extends IntegrationTestStubParent
|
|
0 commit comments