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\Argument\BoundArgument;
16 use Symfony\Component\DependencyInjection\Definition;
17 use Symfony\Component\DependencyInjection\Compiler\CheckExceptionOnInvalidReferenceBehaviorPass;
18 use Symfony\Component\DependencyInjection\Reference;
19 use Symfony\Component\DependencyInjection\ContainerBuilder;
21 class CheckExceptionOnInvalidReferenceBehaviorPassTest extends TestCase
23 public function testProcess()
25 $container = new ContainerBuilder();
28 ->register('a', '\stdClass')
29 ->addArgument(new Reference('b'))
31 $container->register('b', '\stdClass');
33 $this->process($container);
35 $this->addToAssertionCount(1);
39 * @expectedException \Symfony\Component\DependencyInjection\Exception\ServiceNotFoundException
41 public function testProcessThrowsExceptionOnInvalidReference()
43 $container = new ContainerBuilder();
46 ->register('a', '\stdClass')
47 ->addArgument(new Reference('b'))
50 $this->process($container);
54 * @expectedException \Symfony\Component\DependencyInjection\Exception\ServiceNotFoundException
56 public function testProcessThrowsExceptionOnInvalidReferenceFromInlinedDefinition()
58 $container = new ContainerBuilder();
60 $def = new Definition();
61 $def->addArgument(new Reference('b'));
64 ->register('a', '\stdClass')
68 $this->process($container);
72 * @expectedException \Symfony\Component\DependencyInjection\Exception\InvalidArgumentException
73 * @expectedExceptionMessage Invalid ignore-on-uninitialized reference found in service
75 public function testProcessThrowsExceptionOnNonSharedUninitializedReference()
77 $container = new ContainerBuilder();
80 ->register('a', 'stdClass')
81 ->addArgument(new Reference('b', $container::IGNORE_ON_UNINITIALIZED_REFERENCE))
85 ->register('b', 'stdClass')
89 $this->process($container);
92 public function testProcessDefinitionWithBindings()
94 $container = new ContainerBuilder();
98 ->setBindings(array(new BoundArgument(new Reference('a'))))
101 $this->process($container);
103 $this->addToAssertionCount(1);
106 private function process(ContainerBuilder $container)
108 $pass = new CheckExceptionOnInvalidReferenceBehaviorPass();
109 $pass->process($container);