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\Compiler\CheckExceptionOnInvalidReferenceBehaviorPass;
17 use Symfony\Component\DependencyInjection\ContainerBuilder;
18 use Symfony\Component\DependencyInjection\Definition;
19 use Symfony\Component\DependencyInjection\Reference;
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);
71 public function testProcessDefinitionWithBindings()
73 $container = new ContainerBuilder();
77 ->setBindings(array(new BoundArgument(new Reference('a'))))
80 $this->process($container);
82 $this->addToAssertionCount(1);
85 private function process(ContainerBuilder $container)
87 $pass = new CheckExceptionOnInvalidReferenceBehaviorPass();
88 $pass->process($container);