fix a DI circular reference recognition bug
This commit is contained in:
parent
580b249310
commit
8a434edd2c
|
@ -56,11 +56,13 @@ class CheckCircularReferencesPass implements CompilerPassInterface
|
|||
private function checkOutEdges(array $edges)
|
||||
{
|
||||
foreach ($edges as $edge) {
|
||||
$node = $edge->getDestNode();
|
||||
$this->currentPath[] = $id = $node->getId();
|
||||
$node = $edge->getDestNode();
|
||||
$id = $node->getId();
|
||||
$searchKey = array_search($id, $this->currentPath);
|
||||
$this->currentPath[] = $id;
|
||||
|
||||
if ($this->currentId === $id) {
|
||||
throw new ServiceCircularReferenceException($this->currentId, $this->currentPath);
|
||||
if (false !== $searchKey) {
|
||||
throw new ServiceCircularReferenceException($id, array_slice($this->currentPath, $searchKey));
|
||||
}
|
||||
|
||||
$this->checkOutEdges($node->getOutEdges());
|
||||
|
|
|
@ -24,7 +24,7 @@ use Symfony\Component\DependencyInjection\ContainerBuilder;
|
|||
class CheckCircularReferencesPassTest extends \PHPUnit_Framework_TestCase
|
||||
{
|
||||
/**
|
||||
* @expectedException \RuntimeException
|
||||
* @expectedException \Symfony\Component\DependencyInjection\Exception\ServiceCircularReferenceException
|
||||
*/
|
||||
public function testProcess()
|
||||
{
|
||||
|
@ -36,7 +36,7 @@ class CheckCircularReferencesPassTest extends \PHPUnit_Framework_TestCase
|
|||
}
|
||||
|
||||
/**
|
||||
* @expectedException \RuntimeException
|
||||
* @expectedException \Symfony\Component\DependencyInjection\Exception\ServiceCircularReferenceException
|
||||
*/
|
||||
public function testProcessWithAliases()
|
||||
{
|
||||
|
@ -49,7 +49,7 @@ class CheckCircularReferencesPassTest extends \PHPUnit_Framework_TestCase
|
|||
}
|
||||
|
||||
/**
|
||||
* @expectedException \RuntimeException
|
||||
* @expectedException \Symfony\Component\DependencyInjection\Exception\ServiceCircularReferenceException
|
||||
*/
|
||||
public function testProcessDetectsIndirectCircularReference()
|
||||
{
|
||||
|
@ -61,6 +61,19 @@ class CheckCircularReferencesPassTest extends \PHPUnit_Framework_TestCase
|
|||
$this->process($container);
|
||||
}
|
||||
|
||||
/**
|
||||
* @expectedException \Symfony\Component\DependencyInjection\Exception\ServiceCircularReferenceException
|
||||
*/
|
||||
public function testDeepCircularReference()
|
||||
{
|
||||
$container = new ContainerBuilder();
|
||||
$container->register('a')->addArgument(new Reference('b'));
|
||||
$container->register('b')->addArgument(new Reference('c'));
|
||||
$container->register('c')->addArgument(new Reference('b'));
|
||||
|
||||
$this->process($container);
|
||||
}
|
||||
|
||||
public function testProcessIgnoresMethodCalls()
|
||||
{
|
||||
$container = new ContainerBuilder();
|
||||
|
|
Reference in New Issue