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)
|
private function checkOutEdges(array $edges)
|
||||||
{
|
{
|
||||||
foreach ($edges as $edge) {
|
foreach ($edges as $edge) {
|
||||||
$node = $edge->getDestNode();
|
$node = $edge->getDestNode();
|
||||||
$this->currentPath[] = $id = $node->getId();
|
$id = $node->getId();
|
||||||
|
$searchKey = array_search($id, $this->currentPath);
|
||||||
|
$this->currentPath[] = $id;
|
||||||
|
|
||||||
if ($this->currentId === $id) {
|
if (false !== $searchKey) {
|
||||||
throw new ServiceCircularReferenceException($this->currentId, $this->currentPath);
|
throw new ServiceCircularReferenceException($id, array_slice($this->currentPath, $searchKey));
|
||||||
}
|
}
|
||||||
|
|
||||||
$this->checkOutEdges($node->getOutEdges());
|
$this->checkOutEdges($node->getOutEdges());
|
||||||
|
|
|
@ -24,7 +24,7 @@ use Symfony\Component\DependencyInjection\ContainerBuilder;
|
||||||
class CheckCircularReferencesPassTest extends \PHPUnit_Framework_TestCase
|
class CheckCircularReferencesPassTest extends \PHPUnit_Framework_TestCase
|
||||||
{
|
{
|
||||||
/**
|
/**
|
||||||
* @expectedException \RuntimeException
|
* @expectedException \Symfony\Component\DependencyInjection\Exception\ServiceCircularReferenceException
|
||||||
*/
|
*/
|
||||||
public function testProcess()
|
public function testProcess()
|
||||||
{
|
{
|
||||||
|
@ -36,7 +36,7 @@ class CheckCircularReferencesPassTest extends \PHPUnit_Framework_TestCase
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @expectedException \RuntimeException
|
* @expectedException \Symfony\Component\DependencyInjection\Exception\ServiceCircularReferenceException
|
||||||
*/
|
*/
|
||||||
public function testProcessWithAliases()
|
public function testProcessWithAliases()
|
||||||
{
|
{
|
||||||
|
@ -49,7 +49,7 @@ class CheckCircularReferencesPassTest extends \PHPUnit_Framework_TestCase
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @expectedException \RuntimeException
|
* @expectedException \Symfony\Component\DependencyInjection\Exception\ServiceCircularReferenceException
|
||||||
*/
|
*/
|
||||||
public function testProcessDetectsIndirectCircularReference()
|
public function testProcessDetectsIndirectCircularReference()
|
||||||
{
|
{
|
||||||
|
@ -61,6 +61,19 @@ class CheckCircularReferencesPassTest extends \PHPUnit_Framework_TestCase
|
||||||
$this->process($container);
|
$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()
|
public function testProcessIgnoresMethodCalls()
|
||||||
{
|
{
|
||||||
$container = new ContainerBuilder();
|
$container = new ContainerBuilder();
|
||||||
|
|
Reference in New Issue