4 * This file is part of the Symfony package.
6 * (c) Fabien Potencier <fabien@symfony.com>
8 * For the full copyright and license information, please view the LICENSE
9 * file that was distributed with this source code.
12 namespace Symfony\Component\DependencyInjection\Tests\Compiler;
14 use PHPUnit\Framework\TestCase;
15 use Symfony\Component\DependencyInjection\ContainerInterface;
16 use Symfony\Component\DependencyInjection\Reference;
17 use Symfony\Component\DependencyInjection\Compiler\ResolveInvalidReferencesPass;
18 use Symfony\Component\DependencyInjection\ContainerBuilder;
20 class ResolveInvalidReferencesPassTest extends TestCase
22 public function testProcess()
24 $container = new ContainerBuilder();
27 ->setArguments(array(new Reference('bar', ContainerInterface::NULL_ON_INVALID_REFERENCE)))
28 ->addMethodCall('foo', array(new Reference('moo', ContainerInterface::IGNORE_ON_INVALID_REFERENCE)))
31 $this->process($container);
33 $arguments = $def->getArguments();
34 $this->assertNull($arguments[0]);
35 $this->assertCount(0, $def->getMethodCalls());
38 public function testProcessIgnoreNonExistentServices()
40 $container = new ContainerBuilder();
43 ->setArguments(array(new Reference('bar')))
46 $this->process($container);
48 $arguments = $def->getArguments();
49 $this->assertEquals('bar', (string) $arguments[0]);
52 public function testProcessRemovesPropertiesOnInvalid()
54 $container = new ContainerBuilder();
57 ->setProperty('foo', new Reference('bar', ContainerInterface::IGNORE_ON_INVALID_REFERENCE))
60 $this->process($container);
62 $this->assertEquals(array(), $def->getProperties());
68 public function testStrictFlagIsPreserved()
70 $container = new ContainerBuilder();
71 $container->register('bar');
74 ->addArgument(new Reference('bar', ContainerInterface::NULL_ON_INVALID_REFERENCE, false))
77 $this->process($container);
79 $this->assertFalse($def->getArgument(0)->isStrict());
82 protected function process(ContainerBuilder $container)
84 $pass = new ResolveInvalidReferencesPass();
85 $pass->process($container);