Updated Drupal to 8.6. This goes with the following updates because it's possible...
[yaffs-website] / vendor / symfony / dependency-injection / Tests / ChildDefinitionTest.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\ChildDefinition;
16 use Symfony\Component\DependencyInjection\DefinitionDecorator;
17
18 class ChildDefinitionTest extends TestCase
19 {
20     public function testConstructor()
21     {
22         $def = new ChildDefinition('foo');
23
24         $this->assertSame('foo', $def->getParent());
25         $this->assertSame(array(), $def->getChanges());
26     }
27
28     /**
29      * @dataProvider getPropertyTests
30      */
31     public function testSetProperty($property, $changeKey)
32     {
33         $def = new ChildDefinition('foo');
34
35         $getter = 'get'.ucfirst($property);
36         $setter = 'set'.ucfirst($property);
37
38         $this->assertNull($def->$getter());
39         $this->assertSame($def, $def->$setter('foo'));
40         $this->assertSame('foo', $def->$getter());
41         $this->assertSame(array($changeKey => true), $def->getChanges());
42     }
43
44     public function getPropertyTests()
45     {
46         return array(
47             array('class', 'class'),
48             array('factory', 'factory'),
49             array('configurator', 'configurator'),
50             array('file', 'file'),
51         );
52     }
53
54     public function testSetPublic()
55     {
56         $def = new ChildDefinition('foo');
57
58         $this->assertTrue($def->isPublic());
59         $this->assertSame($def, $def->setPublic(false));
60         $this->assertFalse($def->isPublic());
61         $this->assertSame(array('public' => true), $def->getChanges());
62     }
63
64     public function testSetLazy()
65     {
66         $def = new ChildDefinition('foo');
67
68         $this->assertFalse($def->isLazy());
69         $this->assertSame($def, $def->setLazy(false));
70         $this->assertFalse($def->isLazy());
71         $this->assertSame(array('lazy' => true), $def->getChanges());
72     }
73
74     public function testSetAutowired()
75     {
76         $def = new ChildDefinition('foo');
77
78         $this->assertFalse($def->isAutowired());
79         $this->assertSame($def, $def->setAutowired(true));
80         $this->assertTrue($def->isAutowired());
81         $this->assertSame(array('autowired' => true), $def->getChanges());
82     }
83
84     public function testSetArgument()
85     {
86         $def = new ChildDefinition('foo');
87
88         $this->assertSame(array(), $def->getArguments());
89         $this->assertSame($def, $def->replaceArgument(0, 'foo'));
90         $this->assertSame(array('index_0' => 'foo'), $def->getArguments());
91     }
92
93     /**
94      * @expectedException \InvalidArgumentException
95      */
96     public function testReplaceArgumentShouldRequireIntegerIndex()
97     {
98         $def = new ChildDefinition('foo');
99
100         $def->replaceArgument('0', 'foo');
101     }
102
103     public function testReplaceArgument()
104     {
105         $def = new ChildDefinition('foo');
106
107         $def->setArguments(array(0 => 'foo', 1 => 'bar'));
108         $this->assertSame('foo', $def->getArgument(0));
109         $this->assertSame('bar', $def->getArgument(1));
110
111         $this->assertSame($def, $def->replaceArgument(1, 'baz'));
112         $this->assertSame('foo', $def->getArgument(0));
113         $this->assertSame('baz', $def->getArgument(1));
114
115         $this->assertSame(array(0 => 'foo', 1 => 'bar', 'index_1' => 'baz'), $def->getArguments());
116
117         $this->assertSame($def, $def->replaceArgument('$bar', 'val'));
118         $this->assertSame('val', $def->getArgument('$bar'));
119         $this->assertSame(array(0 => 'foo', 1 => 'bar', 'index_1' => 'baz', '$bar' => 'val'), $def->getArguments());
120     }
121
122     /**
123      * @expectedException \OutOfBoundsException
124      */
125     public function testGetArgumentShouldCheckBounds()
126     {
127         $def = new ChildDefinition('foo');
128
129         $def->setArguments(array(0 => 'foo'));
130         $def->replaceArgument(0, 'foo');
131
132         $def->getArgument(1);
133     }
134
135     public function testDefinitionDecoratorAliasExistsForBackwardsCompatibility()
136     {
137         $this->assertInstanceOf(ChildDefinition::class, new DefinitionDecorator('foo'));
138     }
139
140     /**
141      * @expectedException \Symfony\Component\DependencyInjection\Exception\BadMethodCallException
142      */
143     public function testCannotCallSetAutoconfigured()
144     {
145         $def = new ChildDefinition('foo');
146         $def->setAutoconfigured(true);
147     }
148
149     /**
150      * @expectedException \Symfony\Component\DependencyInjection\Exception\BadMethodCallException
151      */
152     public function testCannotCallSetInstanceofConditionals()
153     {
154         $def = new ChildDefinition('foo');
155         $def->setInstanceofConditionals(array('Foo' => new ChildDefinition('')));
156     }
157 }