namespace Symfony\Component\DependencyInjection\Tests\Compiler;
use PHPUnit\Framework\TestCase;
+use Symfony\Component\DependencyInjection\Argument\IteratorArgument;
use Symfony\Component\DependencyInjection\Definition;
use Symfony\Component\DependencyInjection\Compiler\AnalyzeServiceReferencesPass;
use Symfony\Component\DependencyInjection\Compiler\RepeatedPass;
$this->assertSame($ref6, $edges[3]->getValue());
}
+ public function testProcessMarksEdgesLazyWhenReferencedServiceIsLazy()
+ {
+ $container = new ContainerBuilder();
+
+ $container
+ ->register('a')
+ ->setLazy(true)
+ ->addArgument($ref1 = new Reference('b'))
+ ;
+
+ $container
+ ->register('b')
+ ->addArgument($ref2 = new Reference('a'))
+ ;
+
+ $graph = $this->process($container);
+
+ $this->assertCount(1, $graph->getNode('b')->getInEdges());
+ $this->assertCount(1, $edges = $graph->getNode('a')->getInEdges());
+
+ $this->assertSame($ref2, $edges[0]->getValue());
+ $this->assertTrue($edges[0]->isLazy());
+ }
+
+ public function testProcessMarksEdgesLazyWhenReferencedFromIteratorArgument()
+ {
+ $container = new ContainerBuilder();
+ $container->register('a');
+ $container->register('b');
+
+ $container
+ ->register('c')
+ ->addArgument($ref1 = new Reference('a'))
+ ->addArgument(new IteratorArgument(array($ref2 = new Reference('b'))))
+ ;
+
+ $graph = $this->process($container);
+
+ $this->assertCount(1, $graph->getNode('a')->getInEdges());
+ $this->assertCount(1, $graph->getNode('b')->getInEdges());
+ $this->assertCount(2, $edges = $graph->getNode('c')->getOutEdges());
+
+ $this->assertSame($ref1, $edges[0]->getValue());
+ $this->assertFalse($edges[0]->isLazy());
+ $this->assertSame($ref2, $edges[1]->getValue());
+ $this->assertTrue($edges[1]->isLazy());
+ }
+
public function testProcessDetectsReferencesFromInlinedDefinitions()
{
$container = new ContainerBuilder();
$this->assertSame($ref, $refs[0]->getValue());
}
+ public function testProcessDetectsReferencesFromIteratorArguments()
+ {
+ $container = new ContainerBuilder();
+
+ $container
+ ->register('a')
+ ;
+
+ $container
+ ->register('b')
+ ->addArgument(new IteratorArgument(array($ref = new Reference('a'))))
+ ;
+
+ $graph = $this->process($container);
+
+ $this->assertCount(1, $refs = $graph->getNode('a')->getInEdges());
+ $this->assertSame($ref, $refs[0]->getValue());
+ }
+
public function testProcessDetectsReferencesFromInlinedFactoryDefinitions()
{
$container = new ContainerBuilder();