This repository has been archived on 2023-08-20. You can view files and clone it, but cannot push or open issues or pull requests.
symfony/tests/Symfony/Tests/Component/DependencyInjection/Compiler/CheckCircularReferencesPassTest.php
Fabien Potencier 17cd08dc6c fixed CS
2011-06-08 19:56:59 +02:00

73 lines
2.1 KiB
PHP

<?php
/*
* This file is part of the Symfony framework.
*
* (c) Fabien Potencier <fabien@symfony.com>
*
* This source file is subject to the MIT license that is bundled
* with this source code in the file LICENSE.
*/
namespace Symfony\Tests\Component\DependencyInjection\Compiler;
use Symfony\Component\DependencyInjection\Reference;
use Symfony\Component\DependencyInjection\Compiler\CheckCircularReferencesPass;
use Symfony\Component\DependencyInjection\Compiler\AnalyzeServiceReferencesPass;
use Symfony\Component\DependencyInjection\Compiler\Compiler;
use Symfony\Component\DependencyInjection\ContainerBuilder;
class CheckCircularReferencesPassTest extends \PHPUnit_Framework_TestCase
{
/**
* @expectedException \RuntimeException
*/
public function testProcess()
{
$container = new ContainerBuilder();
$container->register('a')->addArgument(new Reference('b'));
$container->register('b')->addArgument(new Reference('a'));
$this->process($container);
}
/**
* @expectedException \RuntimeException
*/
public function testProcessDetectsIndirectCircularReference()
{
$container = new ContainerBuilder();
$container->register('a')->addArgument(new Reference('b'));
$container->register('b')->addArgument(new Reference('c'));
$container->register('c')->addArgument(new Reference('a'));
$this->process($container);
}
public function testProcessIgnoresMethodCalls()
{
$container = new ContainerBuilder();
$container->register('a')->addArgument(new Reference('b'));
$container->register('b')->addMethodCall('setA', array(new Reference('a')));
$this->process($container);
}
protected function process(ContainerBuilder $container)
{
$compiler = new Compiler();
$passConfig = $compiler->getPassConfig();
$passConfig->setOptimizationPasses(array(
new AnalyzeServiceReferencesPass(true),
new CheckCircularReferencesPass(),
));
$passConfig->setRemovingPasses(array());
$compiler->compile($container);
}
}