class CheckCircularReferencesPassTest in Service Container 7.2
Same name and namespace in other branches
- 7 modules/providers/service_container_symfony/lib/Symfony/Component/DependencyInjection/Tests/Compiler/CheckCircularReferencesPassTest.php \Symfony\Component\DependencyInjection\Tests\Compiler\CheckCircularReferencesPassTest
Hierarchy
- class \Symfony\Component\DependencyInjection\Tests\Compiler\CheckCircularReferencesPassTest extends \Symfony\Component\DependencyInjection\Tests\Compiler\PHPUnit_Framework_TestCase
Expanded class hierarchy of CheckCircularReferencesPassTest
File
- modules/
providers/ service_container_symfony/ lib/ Symfony/ Component/ DependencyInjection/ Tests/ Compiler/ CheckCircularReferencesPassTest.php, line 20
Namespace
Symfony\Component\DependencyInjection\Tests\CompilerView source
class CheckCircularReferencesPassTest extends \PHPUnit_Framework_TestCase {
/**
* @expectedException \Symfony\Component\DependencyInjection\Exception\ServiceCircularReferenceException
*/
public function testProcess() {
$container = new ContainerBuilder();
$container
->register('a')
->addArgument(new Reference('b'));
$container
->register('b')
->addArgument(new Reference('a'));
$this
->process($container);
}
/**
* @expectedException \Symfony\Component\DependencyInjection\Exception\ServiceCircularReferenceException
*/
public function testProcessWithAliases() {
$container = new ContainerBuilder();
$container
->register('a')
->addArgument(new Reference('b'));
$container
->setAlias('b', 'c');
$container
->setAlias('c', 'a');
$this
->process($container);
}
/**
* @expectedException \Symfony\Component\DependencyInjection\Exception\ServiceCircularReferenceException
*/
public function testProcessWithFactory() {
$container = new ContainerBuilder();
$container
->register('a', 'stdClass')
->setFactory(array(
new Reference('b'),
'getInstance',
));
$container
->register('b', 'stdClass')
->setFactory(array(
new Reference('a'),
'getInstance',
));
$this
->process($container);
}
/**
* @expectedException \Symfony\Component\DependencyInjection\Exception\ServiceCircularReferenceException
*/
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);
}
/**
* @expectedException \Symfony\Component\DependencyInjection\Exception\ServiceCircularReferenceException
*/
public function testProcessDetectsIndirectCircularReferenceWithFactory() {
$container = new ContainerBuilder();
$container
->register('a')
->addArgument(new Reference('b'));
$container
->register('b', 'stdClass')
->setFactory(array(
new Reference('c'),
'getInstance',
));
$container
->register('c')
->addArgument(new Reference('a'));
$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();
$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);
}
}