Updated to Drupal 8.5. Core Media not yet in use.
[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\Definition;
17 use Symfony\Component\DependencyInjection\Compiler\CheckExceptionOnInvalidReferenceBehaviorPass;
18 use Symfony\Component\DependencyInjection\Reference;
19 use Symfony\Component\DependencyInjection\ContainerBuilder;
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     /**
72      * @expectedException \Symfony\Component\DependencyInjection\Exception\InvalidArgumentException
73      * @expectedExceptionMessage Invalid ignore-on-uninitialized reference found in service
74      */
75     public function testProcessThrowsExceptionOnNonSharedUninitializedReference()
76     {
77         $container = new ContainerBuilder();
78
79         $container
80             ->register('a', 'stdClass')
81             ->addArgument(new Reference('b', $container::IGNORE_ON_UNINITIALIZED_REFERENCE))
82         ;
83
84         $container
85             ->register('b', 'stdClass')
86             ->setShared(false)
87         ;
88
89         $this->process($container);
90     }
91
92     public function testProcessDefinitionWithBindings()
93     {
94         $container = new ContainerBuilder();
95
96         $container
97             ->register('b')
98             ->setBindings(array(new BoundArgument(new Reference('a'))))
99         ;
100
101         $this->process($container);
102
103         $this->addToAssertionCount(1);
104     }
105
106     private function process(ContainerBuilder $container)
107     {
108         $pass = new CheckExceptionOnInvalidReferenceBehaviorPass();
109         $pass->process($container);
110     }
111 }