diff --git a/src/Symfony/Component/DependencyInjection/Compiler/PassConfig.php b/src/Symfony/Component/DependencyInjection/Compiler/PassConfig.php index c03ff9deb71d3..6daa4b7546448 100644 --- a/src/Symfony/Component/DependencyInjection/Compiler/PassConfig.php +++ b/src/Symfony/Component/DependencyInjection/Compiler/PassConfig.php @@ -63,6 +63,7 @@ public function __construct() new RemoveUnusedDefinitionsPass(), )), new CheckExceptionOnInvalidReferenceBehaviorPass(), + new CheckCircularReferencesPass(), ); } diff --git a/src/Symfony/Component/DependencyInjection/Tests/Compiler/IntegrationTest.php b/src/Symfony/Component/DependencyInjection/Tests/Compiler/IntegrationTest.php index c4479403aa3d7..c4eee4033ef9a 100644 --- a/src/Symfony/Component/DependencyInjection/Tests/Compiler/IntegrationTest.php +++ b/src/Symfony/Component/DependencyInjection/Tests/Compiler/IntegrationTest.php @@ -113,4 +113,30 @@ public function testProcessInlinesWhenThereAreMultipleReferencesButFromTheSameDe $this->assertFalse($container->hasDefinition('b')); $this->assertFalse($container->hasDefinition('c'), 'Service C was not inlined.'); } + + /** + * @expectedException \Symfony\Component\DependencyInjection\Exception\ServiceCircularReferenceException + */ + public function testCircularReferencesCausedByMethodCallsAreDetectedDuringCompilation() + { + $container = new ContainerBuilder(); + $container->setResourceTracking(false); + + $container + ->register('foobar', '\stdClass') + ->addArgument(new Reference('foo')) + ; + + $container + ->register('foo', '\stdClass') + ->addArgument(new Reference('bar')) + ; + + $container + ->register('foo', '\stdClass') + ->addMethodCall('addFoobar', array(new Reference('foobar'))) + ; + + $container->compile(); + } } diff --git a/src/Symfony/Component/DependencyInjection/Tests/Fixtures/containers/container9.php b/src/Symfony/Component/DependencyInjection/Tests/Fixtures/containers/container9.php index 695f2875ffdf4..3db661cf8c457 100644 --- a/src/Symfony/Component/DependencyInjection/Tests/Fixtures/containers/container9.php +++ b/src/Symfony/Component/DependencyInjection/Tests/Fixtures/containers/container9.php @@ -64,7 +64,6 @@ ; $container ->register('baz', 'Baz') - ->addMethodCall('setFoo', array(new Reference('foo_with_inline'))) ; $container ->register('request', 'Request') diff --git a/src/Symfony/Component/DependencyInjection/Tests/Fixtures/graphviz/services9.dot b/src/Symfony/Component/DependencyInjection/Tests/Fixtures/graphviz/services9.dot index b3b424e2e73c7..49de5aa2f59b2 100644 --- a/src/Symfony/Component/DependencyInjection/Tests/Fixtures/graphviz/services9.dot +++ b/src/Symfony/Component/DependencyInjection/Tests/Fixtures/graphviz/services9.dot @@ -36,6 +36,5 @@ digraph sc { node_method_call1 -> node_foobaz [label="setBar()" style="dashed"]; node_foo_with_inline -> node_inlined [label="setBar()" style="dashed"]; node_inlined -> node_baz [label="setBaz()" style="dashed"]; - node_baz -> node_foo_with_inline [label="setFoo()" style="dashed"]; node_configurator_service -> node_baz [label="setFoo()" style="dashed"]; } diff --git a/src/Symfony/Component/DependencyInjection/Tests/Fixtures/php/services9.php b/src/Symfony/Component/DependencyInjection/Tests/Fixtures/php/services9.php index ce8930b8ddeba..107812974cbd6 100644 --- a/src/Symfony/Component/DependencyInjection/Tests/Fixtures/php/services9.php +++ b/src/Symfony/Component/DependencyInjection/Tests/Fixtures/php/services9.php @@ -80,11 +80,7 @@ protected function getBarService() */ protected function getBazService() { - $this->services['baz'] = $instance = new \Baz(); - - $instance->setFoo($this->get('foo_with_inline')); - - return $instance; + return $this->services['baz'] = new \Baz(); } /** diff --git a/src/Symfony/Component/DependencyInjection/Tests/Fixtures/php/services9_compiled.php b/src/Symfony/Component/DependencyInjection/Tests/Fixtures/php/services9_compiled.php index 559560fa6da60..9592ed87af812 100644 --- a/src/Symfony/Component/DependencyInjection/Tests/Fixtures/php/services9_compiled.php +++ b/src/Symfony/Component/DependencyInjection/Tests/Fixtures/php/services9_compiled.php @@ -99,11 +99,7 @@ protected function getBarService() */ protected function getBazService() { - $this->services['baz'] = $instance = new \Baz(); - - $instance->setFoo($this->get('foo_with_inline')); - - return $instance; + return $this->services['baz'] = new \Baz(); } /** @@ -227,12 +223,11 @@ protected function getFooBarService() protected function getFooWithInlineService() { $a = new \Bar(); - - $this->services['foo_with_inline'] = $instance = new \Foo(); - $a->pub = 'pub'; $a->setBaz($this->get('baz')); + $this->services['foo_with_inline'] = $instance = new \Foo(); + $instance->setBar($a); return $instance; diff --git a/src/Symfony/Component/DependencyInjection/Tests/Fixtures/xml/services9.xml b/src/Symfony/Component/DependencyInjection/Tests/Fixtures/xml/services9.xml index cba6814126f87..f2dadb42471ab 100644 --- a/src/Symfony/Component/DependencyInjection/Tests/Fixtures/xml/services9.xml +++ b/src/Symfony/Component/DependencyInjection/Tests/Fixtures/xml/services9.xml @@ -70,11 +70,7 @@ - - - - - + diff --git a/src/Symfony/Component/DependencyInjection/Tests/Fixtures/yaml/services9.yml b/src/Symfony/Component/DependencyInjection/Tests/Fixtures/yaml/services9.yml index 84f62d25c0fd3..a7a3234855877 100644 --- a/src/Symfony/Component/DependencyInjection/Tests/Fixtures/yaml/services9.yml +++ b/src/Symfony/Component/DependencyInjection/Tests/Fixtures/yaml/services9.yml @@ -52,8 +52,6 @@ services: baz: class: Baz - calls: - - [setFoo, ['@foo_with_inline']] request: class: Request