Yaffs site version 1.1
[yaffs-website] / vendor / symfony / dependency-injection / Tests / Compiler / CheckReferenceValidityPassTest.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\Scope;
16 use Symfony\Component\DependencyInjection\Compiler\CheckReferenceValidityPass;
17 use Symfony\Component\DependencyInjection\ContainerInterface;
18 use Symfony\Component\DependencyInjection\Reference;
19 use Symfony\Component\DependencyInjection\ContainerBuilder;
20
21 class CheckReferenceValidityPassTest extends TestCase
22 {
23     /**
24      * @group legacy
25      */
26     public function testProcessIgnoresScopeWideningIfNonStrictReference()
27     {
28         $container = new ContainerBuilder();
29         $container->register('a')->addArgument(new Reference('b', ContainerInterface::EXCEPTION_ON_INVALID_REFERENCE, false));
30         $container->register('b')->setScope('prototype');
31
32         $this->process($container);
33
34         $this->addToAssertionCount(1);
35     }
36
37     /**
38      * @expectedException \RuntimeException
39      * @group legacy
40      */
41     public function testProcessDetectsScopeWidening()
42     {
43         $container = new ContainerBuilder();
44         $container->register('a')->addArgument(new Reference('b'));
45         $container->register('b')->setScope('prototype');
46
47         $this->process($container);
48
49         $this->addToAssertionCount(1);
50     }
51
52     /**
53      * @group legacy
54      */
55     public function testProcessIgnoresCrossScopeHierarchyReferenceIfNotStrict()
56     {
57         $container = new ContainerBuilder();
58         $container->addScope(new Scope('a'));
59         $container->addScope(new Scope('b'));
60
61         $container->register('a')->setScope('a')->addArgument(new Reference('b', ContainerInterface::EXCEPTION_ON_INVALID_REFERENCE, false));
62         $container->register('b')->setScope('b');
63
64         $this->process($container);
65
66         $this->addToAssertionCount(1);
67     }
68
69     /**
70      * @expectedException \RuntimeException
71      * @group legacy
72      */
73     public function testProcessDetectsCrossScopeHierarchyReference()
74     {
75         $container = new ContainerBuilder();
76         $container->addScope(new Scope('a'));
77         $container->addScope(new Scope('b'));
78
79         $container->register('a')->setScope('a')->addArgument(new Reference('b'));
80         $container->register('b')->setScope('b');
81
82         $this->process($container);
83     }
84
85     /**
86      * @expectedException \RuntimeException
87      */
88     public function testProcessDetectsReferenceToAbstractDefinition()
89     {
90         $container = new ContainerBuilder();
91
92         $container->register('a')->setAbstract(true);
93         $container->register('b')->addArgument(new Reference('a'));
94
95         $this->process($container);
96     }
97
98     public function testProcess()
99     {
100         $container = new ContainerBuilder();
101         $container->register('a')->addArgument(new Reference('b'));
102         $container->register('b');
103
104         $this->process($container);
105
106         $this->addToAssertionCount(1);
107     }
108
109     protected function process(ContainerBuilder $container)
110     {
111         $pass = new CheckReferenceValidityPass();
112         $pass->process($container);
113     }
114 }