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