Security update for Core, with self-updated composer
[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\ContainerBuilder;
17
18 class CheckDefinitionValidityPassTest extends TestCase
19 {
20     /**
21      * @expectedException \Symfony\Component\DependencyInjection\Exception\RuntimeException
22      */
23     public function testProcessDetectsSyntheticNonPublicDefinitions()
24     {
25         $container = new ContainerBuilder();
26         $container->register('a')->setSynthetic(true)->setPublic(false);
27
28         $this->process($container);
29     }
30
31     /**
32      * @expectedException \Symfony\Component\DependencyInjection\Exception\RuntimeException
33      */
34     public function testProcessDetectsNonSyntheticNonAbstractDefinitionWithoutClass()
35     {
36         $container = new ContainerBuilder();
37         $container->register('a')->setSynthetic(false)->setAbstract(false);
38
39         $this->process($container);
40     }
41
42     public function testProcess()
43     {
44         $container = new ContainerBuilder();
45         $container->register('a', 'class');
46         $container->register('b', 'class')->setSynthetic(true)->setPublic(true);
47         $container->register('c', 'class')->setAbstract(true);
48         $container->register('d', 'class')->setSynthetic(true);
49
50         $this->process($container);
51
52         $this->addToAssertionCount(1);
53     }
54
55     public function testValidTags()
56     {
57         $container = new ContainerBuilder();
58         $container->register('a', 'class')->addTag('foo', array('bar' => 'baz'));
59         $container->register('b', 'class')->addTag('foo', array('bar' => null));
60         $container->register('c', 'class')->addTag('foo', array('bar' => 1));
61         $container->register('d', 'class')->addTag('foo', array('bar' => 1.1));
62
63         $this->process($container);
64
65         $this->addToAssertionCount(1);
66     }
67
68     /**
69      * @expectedException \Symfony\Component\DependencyInjection\Exception\RuntimeException
70      */
71     public function testInvalidTags()
72     {
73         $container = new ContainerBuilder();
74         $container->register('a', 'class')->addTag('foo', array('bar' => array('baz' => 'baz')));
75
76         $this->process($container);
77     }
78
79     protected function process(ContainerBuilder $container)
80     {
81         $pass = new CheckDefinitionValidityPass();
82         $pass->process($container);
83     }
84 }