Yaffs site version 1.1
[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     /**
54      * @dataProvider provideLegacyPropertyTests
55      * @group legacy
56      */
57     public function testLegacySetProperty($property, $changeKey)
58     {
59         $def = new DefinitionDecorator('foo');
60
61         $getter = 'get'.ucfirst($property);
62         $setter = 'set'.ucfirst($property);
63
64         $this->assertNull($def->$getter());
65         $this->assertSame($def, $def->$setter('foo'));
66         $this->assertEquals('foo', $def->$getter());
67         $this->assertEquals(array($changeKey => true), $def->getChanges());
68     }
69
70     public function provideLegacyPropertyTests()
71     {
72         return array(
73             array('factoryClass', 'factory_class'),
74             array('factoryMethod', 'factory_method'),
75             array('factoryService', 'factory_service'),
76         );
77     }
78
79     public function testSetPublic()
80     {
81         $def = new DefinitionDecorator('foo');
82
83         $this->assertTrue($def->isPublic());
84         $this->assertSame($def, $def->setPublic(false));
85         $this->assertFalse($def->isPublic());
86         $this->assertEquals(array('public' => true), $def->getChanges());
87     }
88
89     public function testSetLazy()
90     {
91         $def = new DefinitionDecorator('foo');
92
93         $this->assertFalse($def->isLazy());
94         $this->assertSame($def, $def->setLazy(false));
95         $this->assertFalse($def->isLazy());
96         $this->assertEquals(array('lazy' => true), $def->getChanges());
97     }
98
99     public function testSetAutowired()
100     {
101         $def = new DefinitionDecorator('foo');
102
103         $this->assertFalse($def->isAutowired());
104         $this->assertSame($def, $def->setAutowired(false));
105         $this->assertFalse($def->isAutowired());
106         $this->assertEquals(array('autowire' => true), $def->getChanges());
107     }
108
109     public function testSetArgument()
110     {
111         $def = new DefinitionDecorator('foo');
112
113         $this->assertEquals(array(), $def->getArguments());
114         $this->assertSame($def, $def->replaceArgument(0, 'foo'));
115         $this->assertEquals(array('index_0' => 'foo'), $def->getArguments());
116     }
117
118     /**
119      * @expectedException \InvalidArgumentException
120      */
121     public function testReplaceArgumentShouldRequireIntegerIndex()
122     {
123         $def = new DefinitionDecorator('foo');
124
125         $def->replaceArgument('0', 'foo');
126     }
127
128     public function testReplaceArgument()
129     {
130         $def = new DefinitionDecorator('foo');
131
132         $def->setArguments(array(0 => 'foo', 1 => 'bar'));
133         $this->assertEquals('foo', $def->getArgument(0));
134         $this->assertEquals('bar', $def->getArgument(1));
135
136         $this->assertSame($def, $def->replaceArgument(1, 'baz'));
137         $this->assertEquals('foo', $def->getArgument(0));
138         $this->assertEquals('baz', $def->getArgument(1));
139
140         $this->assertEquals(array(0 => 'foo', 1 => 'bar', 'index_1' => 'baz'), $def->getArguments());
141     }
142
143     /**
144      * @expectedException \OutOfBoundsException
145      */
146     public function testGetArgumentShouldCheckBounds()
147     {
148         $def = new DefinitionDecorator('foo');
149
150         $def->setArguments(array(0 => 'foo'));
151         $def->replaceArgument(0, 'foo');
152
153         $def->getArgument(1);
154     }
155 }