|
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.
|
@@ -142,6 +143,29 @@ public function testCanDecorateServiceSubscriber()
|
142 | 143 | $this->assertInstanceOf(DecoratedServiceSubscriber::class, $container->get(ServiceSubscriberStub::class));
|
143 | 144 | }
|
144 | 145 |
|
| 146 | + public function testCanDecorateServiceLocator() |
| 147 | + { |
| 148 | + $container = new ContainerBuilder(); |
| 149 | + |
| 150 | + $container->register('foo', 'stdClass')->setPublic(true); |
| 151 | + |
| 152 | + $container->register(ServiceLocator::class) |
| 153 | + ->addTag('container.service_locator') |
| 154 | + ->setArguments([[new Reference('foo')]]) |
| 155 | + ; |
| 156 | + |
| 157 | + $container->register(DecoratedServiceLocator::class) |
| 158 | + ->setDecoratedService(ServiceLocator::class) |
| 159 | + ->setPublic(true) |
| 160 | + ->setArguments([new Reference(DecoratedServiceLocator::class.'.inner')]) |
| 161 | + ; |
| 162 | + |
| 163 | + $container->compile(); |
| 164 | + |
| 165 | + $this->assertInstanceOf(DecoratedServiceLocator::class, $container->get(DecoratedServiceLocator::class)); |
| 166 | + $this->assertSame($container->get('foo'), $container->get(DecoratedServiceLocator::class)->get('foo')); |
| 167 | + } |
| 168 | + |
145 | 169 | /**
|
146 | 170 | * @dataProvider getYamlCompileTests
|
147 | 171 | */
|
@@ -416,6 +440,34 @@ class DecoratedServiceSubscriber
|
416 | 440 | {
|
417 | 441 | }
|
418 | 442 |
|
| 443 | +class DecoratedServiceLocator implements ServiceProviderInterface |
| 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 | + } |
| 469 | +} |
| 470 | + |
419 | 471 | class IntegrationTestStub extends IntegrationTestStubParent
|
420 | 472 | {
|
421 | 473 | }
|
|
0 commit comments