7e4d4fa9a8fed5934ca8a5c51607b2c802d3d5a7
[yaffs-website] / vendor / symfony / dependency-injection / Tests / Compiler / CheckDefinitionValidityPassTest.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\Compiler\CheckDefinitionValidityPass;
16 use Symfony\Component\DependencyInjection\ContainerInterface;
17 use Symfony\Component\DependencyInjection\ContainerBuilder;
18
19 class CheckDefinitionValidityPassTest extends TestCase
20 {
21     /**
22      * @expectedException \Symfony\Component\DependencyInjection\Exception\RuntimeException
23      */
24     public function testProcessDetectsSyntheticNonPublicDefinitions()
25     {
26         $container = new ContainerBuilder();
27         $container->register('a')->setSynthetic(true)->setPublic(false);
28
29         $this->process($container);
30     }
31
32     /**
33      * @expectedException \Symfony\Component\DependencyInjection\Exception\RuntimeException
34      * @group legacy
35      */
36     public function testProcessDetectsSyntheticPrototypeDefinitions()
37     {
38         $container = new ContainerBuilder();
39         $container->register('a')->setSynthetic(true)->setScope(ContainerInterface::SCOPE_PROTOTYPE);
40
41         $this->process($container);
42     }
43
44     /**
45      * @expectedException \Symfony\Component\DependencyInjection\Exception\RuntimeException
46      * @group legacy
47      */
48     public function testProcessDetectsSharedPrototypeDefinitions()
49     {
50         $container = new ContainerBuilder();
51         $container->register('a')->setShared(true)->setScope(ContainerInterface::SCOPE_PROTOTYPE);
52
53         $this->process($container);
54     }
55
56     /**
57      * @expectedException \Symfony\Component\DependencyInjection\Exception\RuntimeException
58      */
59     public function testProcessDetectsNonSyntheticNonAbstractDefinitionWithoutClass()
60     {
61         $container = new ContainerBuilder();
62         $container->register('a')->setSynthetic(false)->setAbstract(false);
63
64         $this->process($container);
65     }
66
67     /**
68      * @expectedException \Symfony\Component\DependencyInjection\Exception\RuntimeException
69      * @group legacy
70      */
71     public function testLegacyProcessDetectsBothFactorySyntaxesUsed()
72     {
73         $container = new ContainerBuilder();
74         $container->register('a')->setFactory(array('a', 'b'))->setFactoryClass('a');
75
76         $this->process($container);
77     }
78
79     public function testProcess()
80     {
81         $container = new ContainerBuilder();
82         $container->register('a', 'class');
83         $container->register('b', 'class')->setSynthetic(true)->setPublic(true);
84         $container->register('c', 'class')->setAbstract(true);
85         $container->register('d', 'class')->setSynthetic(true);
86
87         $this->process($container);
88
89         $this->addToAssertionCount(1);
90     }
91
92     public function testValidTags()
93     {
94         $container = new ContainerBuilder();
95         $container->register('a', 'class')->addTag('foo', array('bar' => 'baz'));
96         $container->register('b', 'class')->addTag('foo', array('bar' => null));
97         $container->register('c', 'class')->addTag('foo', array('bar' => 1));
98         $container->register('d', 'class')->addTag('foo', array('bar' => 1.1));
99
100         $this->process($container);
101
102         $this->addToAssertionCount(1);
103     }
104
105     /**
106      * @expectedException \Symfony\Component\DependencyInjection\Exception\RuntimeException
107      */
108     public function testInvalidTags()
109     {
110         $container = new ContainerBuilder();
111         $container->register('a', 'class')->addTag('foo', array('bar' => array('baz' => 'baz')));
112
113         $this->process($container);
114     }
115
116     protected function process(ContainerBuilder $container)
117     {
118         $pass = new CheckDefinitionValidityPass();
119         $pass->process($container);
120     }
121 }