65a782a4a83fc96981641e2226c80aa631d9cd85
[yaffs-website] / vendor / symfony / dependency-injection / Tests / Compiler / CheckExceptionOnInvalidReferenceBehaviorPassTest.php
1 <?php
2
3 /*
4  * This file is part of the Symfony package.
5  *
6  * (c) Fabien Potencier <fabien@symfony.com>
7  *
8  * For the full copyright and license information, please view the LICENSE
9  * file that was distributed with this source code.
10  */
11
12 namespace Symfony\Component\DependencyInjection\Tests\Compiler;
13
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;
19
20 class CheckExceptionOnInvalidReferenceBehaviorPassTest extends TestCase
21 {
22     public function testProcess()
23     {
24         $container = new ContainerBuilder();
25
26         $container
27             ->register('a', '\stdClass')
28             ->addArgument(new Reference('b'))
29         ;
30         $container->register('b', '\stdClass');
31
32         $this->process($container);
33
34         $this->addToAssertionCount(1);
35     }
36
37     /**
38      * @expectedException \Symfony\Component\DependencyInjection\Exception\ServiceNotFoundException
39      */
40     public function testProcessThrowsExceptionOnInvalidReference()
41     {
42         $container = new ContainerBuilder();
43
44         $container
45             ->register('a', '\stdClass')
46             ->addArgument(new Reference('b'))
47         ;
48
49         $this->process($container);
50     }
51
52     /**
53      * @expectedException \Symfony\Component\DependencyInjection\Exception\ServiceNotFoundException
54      */
55     public function testProcessThrowsExceptionOnInvalidReferenceFromInlinedDefinition()
56     {
57         $container = new ContainerBuilder();
58
59         $def = new Definition();
60         $def->addArgument(new Reference('b'));
61
62         $container
63             ->register('a', '\stdClass')
64             ->addArgument($def)
65         ;
66
67         $this->process($container);
68     }
69
70     private function process(ContainerBuilder $container)
71     {
72         $pass = new CheckExceptionOnInvalidReferenceBehaviorPass();
73         $pass->process($container);
74     }
75 }