Updated Drupal to 8.6. This goes with the following updates because it's possible...
[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\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;
20
21 class CheckExceptionOnInvalidReferenceBehaviorPassTest extends TestCase
22 {
23     public function testProcess()
24     {
25         $container = new ContainerBuilder();
26
27         $container
28             ->register('a', '\stdClass')
29             ->addArgument(new Reference('b'))
30         ;
31         $container->register('b', '\stdClass');
32
33         $this->process($container);
34
35         $this->addToAssertionCount(1);
36     }
37
38     /**
39      * @expectedException \Symfony\Component\DependencyInjection\Exception\ServiceNotFoundException
40      */
41     public function testProcessThrowsExceptionOnInvalidReference()
42     {
43         $container = new ContainerBuilder();
44
45         $container
46             ->register('a', '\stdClass')
47             ->addArgument(new Reference('b'))
48         ;
49
50         $this->process($container);
51     }
52
53     /**
54      * @expectedException \Symfony\Component\DependencyInjection\Exception\ServiceNotFoundException
55      */
56     public function testProcessThrowsExceptionOnInvalidReferenceFromInlinedDefinition()
57     {
58         $container = new ContainerBuilder();
59
60         $def = new Definition();
61         $def->addArgument(new Reference('b'));
62
63         $container
64             ->register('a', '\stdClass')
65             ->addArgument($def)
66         ;
67
68         $this->process($container);
69     }
70
71     public function testProcessDefinitionWithBindings()
72     {
73         $container = new ContainerBuilder();
74
75         $container
76             ->register('b')
77             ->setBindings(array(new BoundArgument(new Reference('a'))))
78         ;
79
80         $this->process($container);
81
82         $this->addToAssertionCount(1);
83     }
84
85     private function process(ContainerBuilder $container)
86     {
87         $pass = new CheckExceptionOnInvalidReferenceBehaviorPass();
88         $pass->process($container);
89     }
90 }