Security update for Core, with self-updated composer
[yaffs-website] / vendor / symfony / dependency-injection / Tests / DefinitionDecoratorTest.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;
13
14 use PHPUnit\Framework\TestCase;
15 use Symfony\Component\DependencyInjection\DefinitionDecorator;
16
17 class DefinitionDecoratorTest extends TestCase
18 {
19     public function testConstructor()
20     {
21         $def = new DefinitionDecorator('foo');
22
23         $this->assertEquals('foo', $def->getParent());
24         $this->assertEquals(array(), $def->getChanges());
25     }
26
27     /**
28      * @dataProvider getPropertyTests
29      */
30     public function testSetProperty($property, $changeKey)
31     {
32         $def = new DefinitionDecorator('foo');
33
34         $getter = 'get'.ucfirst($property);
35         $setter = 'set'.ucfirst($property);
36
37         $this->assertNull($def->$getter());
38         $this->assertSame($def, $def->$setter('foo'));
39         $this->assertEquals('foo', $def->$getter());
40         $this->assertEquals(array($changeKey => true), $def->getChanges());
41     }
42
43     public function getPropertyTests()
44     {
45         return array(
46             array('class', 'class'),
47             array('factory', 'factory'),
48             array('configurator', 'configurator'),
49             array('file', 'file'),
50         );
51     }
52
53     public function testSetPublic()
54     {
55         $def = new DefinitionDecorator('foo');
56
57         $this->assertTrue($def->isPublic());
58         $this->assertSame($def, $def->setPublic(false));
59         $this->assertFalse($def->isPublic());
60         $this->assertEquals(array('public' => true), $def->getChanges());
61     }
62
63     public function testSetLazy()
64     {
65         $def = new DefinitionDecorator('foo');
66
67         $this->assertFalse($def->isLazy());
68         $this->assertSame($def, $def->setLazy(false));
69         $this->assertFalse($def->isLazy());
70         $this->assertEquals(array('lazy' => true), $def->getChanges());
71     }
72
73     public function testSetAutowired()
74     {
75         $def = new DefinitionDecorator('foo');
76
77         $this->assertFalse($def->isAutowired());
78         $this->assertSame($def, $def->setAutowired(false));
79         $this->assertFalse($def->isAutowired());
80         $this->assertEquals(array('autowire' => true), $def->getChanges());
81     }
82
83     public function testSetArgument()
84     {
85         $def = new DefinitionDecorator('foo');
86
87         $this->assertEquals(array(), $def->getArguments());
88         $this->assertSame($def, $def->replaceArgument(0, 'foo'));
89         $this->assertEquals(array('index_0' => 'foo'), $def->getArguments());
90     }
91
92     /**
93      * @expectedException \InvalidArgumentException
94      */
95     public function testReplaceArgumentShouldRequireIntegerIndex()
96     {
97         $def = new DefinitionDecorator('foo');
98
99         $def->replaceArgument('0', 'foo');
100     }
101
102     public function testReplaceArgument()
103     {
104         $def = new DefinitionDecorator('foo');
105
106         $def->setArguments(array(0 => 'foo', 1 => 'bar'));
107         $this->assertEquals('foo', $def->getArgument(0));
108         $this->assertEquals('bar', $def->getArgument(1));
109
110         $this->assertSame($def, $def->replaceArgument(1, 'baz'));
111         $this->assertEquals('foo', $def->getArgument(0));
112         $this->assertEquals('baz', $def->getArgument(1));
113
114         $this->assertEquals(array(0 => 'foo', 1 => 'bar', 'index_1' => 'baz'), $def->getArguments());
115     }
116
117     /**
118      * @expectedException \OutOfBoundsException
119      */
120     public function testGetArgumentShouldCheckBounds()
121     {
122         $def = new DefinitionDecorator('foo');
123
124         $def->setArguments(array(0 => 'foo'));
125         $def->replaceArgument(0, 'foo');
126
127         $def->getArgument(1);
128     }
129 }