|
13 | 13 |
|
14 | 14 | use PHPUnit\Framework\TestCase;
|
15 | 15 | use Symfony\Component\DependencyInjection\Argument\BoundArgument;
|
| 16 | +use Symfony\Component\DependencyInjection\Argument\ServiceLocatorArgument; |
| 17 | +use Symfony\Component\DependencyInjection\Argument\TaggedIteratorArgument; |
16 | 18 | use Symfony\Component\DependencyInjection\Compiler\ServiceLocatorTagPass;
|
17 | 19 | use Symfony\Component\DependencyInjection\ContainerBuilder;
|
| 20 | +use Symfony\Component\DependencyInjection\Definition; |
18 | 21 | use Symfony\Component\DependencyInjection\Exception\InvalidArgumentException;
|
19 | 22 | use Symfony\Component\DependencyInjection\Reference;
|
20 | 23 | use Symfony\Component\DependencyInjection\ServiceLocator;
|
@@ -143,4 +146,56 @@ public function testBindingsAreCopied()
|
143 | 146 | $this->assertSame(['foo'], array_keys($locator->getBindings()));
|
144 | 147 | $this->assertInstanceOf(BoundArgument::class, $locator->getBindings()['foo']);
|
145 | 148 | }
|
| 149 | + |
| 150 | + public function testIndexedByServiceIdWithDecoration() |
| 151 | + { |
| 152 | + $container = new ContainerBuilder(); |
| 153 | + |
| 154 | + $locator = new Definition(Locator::class); |
| 155 | + $locator->setPublic(true); |
| 156 | + $locator->addArgument(new ServiceLocatorArgument(new TaggedIteratorArgument('test_tag', null, null, true))); |
| 157 | + |
| 158 | + $container->setDefinition(Locator::class, $locator); |
| 159 | + |
| 160 | + $service = new Definition(Service::class); |
| 161 | + $service->setPublic(true); |
| 162 | + $service->addTag('test_tag'); |
| 163 | + |
| 164 | + $container->setDefinition(Service::class, $service); |
| 165 | + |
| 166 | + $decorated = new Definition(Decorated::class); |
| 167 | + $decorated->setPublic(true); |
| 168 | + $decorated->setDecoratedService(Service::class); |
| 169 | + |
| 170 | + $container->setDefinition(Decorated::class, $decorated); |
| 171 | + |
| 172 | + $container->compile(); |
| 173 | + |
| 174 | + /** @var ServiceLocator $locator */ |
| 175 | + $locator = $container->get(Locator::class)->locator; |
| 176 | + static::assertTrue($locator->has(Service::class)); |
| 177 | + static::assertFalse($locator->has(Decorated::class)); |
| 178 | + static::assertInstanceOf(Decorated::class, $locator->get(Service::class)); |
| 179 | + } |
| 180 | +} |
| 181 | + |
| 182 | +class Locator |
| 183 | +{ |
| 184 | + /** |
| 185 | + * @var ServiceLocator |
| 186 | + */ |
| 187 | + public $locator; |
| 188 | + |
| 189 | + public function __construct(ServiceLocator $locator) |
| 190 | + { |
| 191 | + $this->locator = $locator; |
| 192 | + } |
| 193 | +} |
| 194 | + |
| 195 | +class Service |
| 196 | +{ |
| 197 | +} |
| 198 | + |
| 199 | +class DecoratedService |
| 200 | +{ |
146 | 201 | }
|
0 commit comments