|
21 | 21 | use Symfony\Component\DependencyInjection\Argument\ClosureProxyArgument;
|
22 | 22 | use Symfony\Component\DependencyInjection\Argument\IteratorArgument;
|
23 | 23 | use Symfony\Component\DependencyInjection\Argument\RewindableGenerator;
|
| 24 | +use Symfony\Component\DependencyInjection\Argument\ServiceLocatorArgument; |
24 | 25 | use Symfony\Component\DependencyInjection\ChildDefinition;
|
25 | 26 | use Symfony\Component\DependencyInjection\Compiler\PassConfig;
|
26 | 27 | use Symfony\Component\DependencyInjection\ContainerBuilder;
|
|
33 | 34 | use Symfony\Component\DependencyInjection\ParameterBag\ParameterBag;
|
34 | 35 | use Symfony\Component\DependencyInjection\ParameterBag\EnvPlaceholderParameterBag;
|
35 | 36 | use Symfony\Component\Config\Resource\FileResource;
|
| 37 | +use Symfony\Component\DependencyInjection\ServiceLocator; |
36 | 38 | use Symfony\Component\DependencyInjection\Tests\Fixtures\CustomDefinition;
|
37 | 39 | use Symfony\Component\DependencyInjection\Tests\Fixtures\CaseSensitiveClass;
|
38 | 40 | use Symfony\Component\ExpressionLanguage\Expression;
|
@@ -437,6 +439,24 @@ public function testCreateServiceWithIteratorArgument()
|
437 | 439 | $this->assertEquals(1, $i);
|
438 | 440 | }
|
439 | 441 |
|
| 442 | + public function testCreateServiceWithServiceLocatorArgument() |
| 443 | + { |
| 444 | + $builder = new ContainerBuilder(); |
| 445 | + $builder->register('bar', 'stdClass'); |
| 446 | + $builder |
| 447 | + ->register('lazy_context', 'LazyContext') |
| 448 | + ->setArguments(array(new ServiceLocatorArgument(array('bar' => new Reference('bar'), 'invalid' => new Reference('invalid', ContainerInterface::IGNORE_ON_INVALID_REFERENCE))))) |
| 449 | + ; |
| 450 | + |
| 451 | + $lazyContext = $builder->get('lazy_context'); |
| 452 | + $locator = $lazyContext->lazyValues; |
| 453 | + |
| 454 | + $this->assertInstanceOf(ServiceLocator::class, $locator); |
| 455 | + $this->assertInstanceOf('stdClass', $locator->get('bar')); |
| 456 | + $this->assertNull($locator->get('invalid')); |
| 457 | + $this->assertSame($locator->get('bar'), $locator('bar'), '->get() should be used when invoking ServiceLocator'); |
| 458 | + } |
| 459 | + |
440 | 460 | /**
|
441 | 461 | * @expectedException \RuntimeException
|
442 | 462 | */
|
|
0 commit comments