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\Definition;
16 use Symfony\Component\DependencyInjection\Compiler\CheckExceptionOnInvalidReferenceBehaviorPass;
17 use Symfony\Component\DependencyInjection\Reference;
18 use Symfony\Component\DependencyInjection\ContainerBuilder;
20 class CheckExceptionOnInvalidReferenceBehaviorPassTest extends TestCase
22 public function testProcess()
24 $container = new ContainerBuilder();
27 ->register('a', '\stdClass')
28 ->addArgument(new Reference('b'))
30 $container->register('b', '\stdClass');
32 $this->process($container);
34 $this->addToAssertionCount(1);
38 * @expectedException \Symfony\Component\DependencyInjection\Exception\ServiceNotFoundException
40 public function testProcessThrowsExceptionOnInvalidReference()
42 $container = new ContainerBuilder();
45 ->register('a', '\stdClass')
46 ->addArgument(new Reference('b'))
49 $this->process($container);
53 * @expectedException \Symfony\Component\DependencyInjection\Exception\ServiceNotFoundException
55 public function testProcessThrowsExceptionOnInvalidReferenceFromInlinedDefinition()
57 $container = new ContainerBuilder();
59 $def = new Definition();
60 $def->addArgument(new Reference('b'));
63 ->register('a', '\stdClass')
67 $this->process($container);
70 private function process(ContainerBuilder $container)
72 $pass = new CheckExceptionOnInvalidReferenceBehaviorPass();
73 $pass->process($container);