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/src/Symfony/Component/DependencyInjection/Tests/Compiler/ResolveInvalidReferencesPassTest.php

88 lines
2.5 KiB
PHP
Raw Normal View History

2011-01-05 11:13:27 +00:00
<?php
/*
* This file is part of the Symfony package.
*
* (c) Fabien Potencier <fabien@symfony.com>
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*/
namespace Symfony\Component\DependencyInjection\Tests\Compiler;
2011-01-05 11:13:27 +00:00
2017-02-08 07:24:27 +00:00
use PHPUnit\Framework\TestCase;
2011-01-05 11:13:27 +00:00
use Symfony\Component\DependencyInjection\ContainerInterface;
use Symfony\Component\DependencyInjection\Reference;
use Symfony\Component\DependencyInjection\Compiler\ResolveInvalidReferencesPass;
use Symfony\Component\DependencyInjection\ContainerBuilder;
2017-02-08 07:24:27 +00:00
class ResolveInvalidReferencesPassTest extends TestCase
2011-01-05 11:13:27 +00:00
{
public function testProcess()
{
$container = new ContainerBuilder();
$def = $container
->register('foo')
->setArguments(array(new Reference('bar', ContainerInterface::NULL_ON_INVALID_REFERENCE)))
->addMethodCall('foo', array(new Reference('moo', ContainerInterface::IGNORE_ON_INVALID_REFERENCE)))
;
$this->process($container);
$arguments = $def->getArguments();
$this->assertNull($arguments[0]);
$this->assertCount(0, $def->getMethodCalls());
2011-01-05 11:13:27 +00:00
}
public function testProcessIgnoreNonExistentServices()
{
$container = new ContainerBuilder();
$def = $container
->register('foo')
->setArguments(array(new Reference('bar')))
;
$this->process($container);
$arguments = $def->getArguments();
$this->assertEquals('bar', (string) $arguments[0]);
}
2011-03-10 14:31:00 +00:00
public function testProcessRemovesPropertiesOnInvalid()
{
$container = new ContainerBuilder();
$def = $container
->register('foo')
->setProperty('foo', new Reference('bar', ContainerInterface::IGNORE_ON_INVALID_REFERENCE))
;
$this->process($container);
$this->assertEquals(array(), $def->getProperties());
}
/**
* @group legacy
*/
public function testStrictFlagIsPreserved()
{
$container = new ContainerBuilder();
$container->register('bar');
$def = $container
->register('foo')
->addArgument(new Reference('bar', ContainerInterface::NULL_ON_INVALID_REFERENCE, false))
;
$this->process($container);
$this->assertFalse($def->getArgument(0)->isStrict());
}
protected function process(ContainerBuilder $container)
2011-01-05 11:13:27 +00:00
{
$pass = new ResolveInvalidReferencesPass();
2011-01-05 11:13:27 +00:00
$pass->process($container);
}
}