4 * This file is part of the Symfony package.
6 * (c) Fabien Potencier <fabien@symfony.com>
8 * For the full copyright and license information, please view the LICENSE
9 * file that was distributed with this source code.
12 namespace Symfony\Component\DependencyInjection\Tests;
14 use PHPUnit\Framework\TestCase;
15 use Symfony\Component\DependencyInjection\DefinitionDecorator;
17 class DefinitionDecoratorTest extends TestCase
19 public function testConstructor()
21 $def = new DefinitionDecorator('foo');
23 $this->assertEquals('foo', $def->getParent());
24 $this->assertEquals(array(), $def->getChanges());
28 * @dataProvider getPropertyTests
30 public function testSetProperty($property, $changeKey)
32 $def = new DefinitionDecorator('foo');
34 $getter = 'get'.ucfirst($property);
35 $setter = 'set'.ucfirst($property);
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());
43 public function getPropertyTests()
46 array('class', 'class'),
47 array('factory', 'factory'),
48 array('configurator', 'configurator'),
49 array('file', 'file'),
53 public function testSetPublic()
55 $def = new DefinitionDecorator('foo');
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());
63 public function testSetLazy()
65 $def = new DefinitionDecorator('foo');
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());
73 public function testSetAutowired()
75 $def = new DefinitionDecorator('foo');
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());
83 public function testSetArgument()
85 $def = new DefinitionDecorator('foo');
87 $this->assertEquals(array(), $def->getArguments());
88 $this->assertSame($def, $def->replaceArgument(0, 'foo'));
89 $this->assertEquals(array('index_0' => 'foo'), $def->getArguments());
93 * @expectedException \InvalidArgumentException
95 public function testReplaceArgumentShouldRequireIntegerIndex()
97 $def = new DefinitionDecorator('foo');
99 $def->replaceArgument('0', 'foo');
102 public function testReplaceArgument()
104 $def = new DefinitionDecorator('foo');
106 $def->setArguments(array(0 => 'foo', 1 => 'bar'));
107 $this->assertEquals('foo', $def->getArgument(0));
108 $this->assertEquals('bar', $def->getArgument(1));
110 $this->assertSame($def, $def->replaceArgument(1, 'baz'));
111 $this->assertEquals('foo', $def->getArgument(0));
112 $this->assertEquals('baz', $def->getArgument(1));
114 $this->assertEquals(array(0 => 'foo', 1 => 'bar', 'index_1' => 'baz'), $def->getArguments());
118 * @expectedException \OutOfBoundsException
120 public function testGetArgumentShouldCheckBounds()
122 $def = new DefinitionDecorator('foo');
124 $def->setArguments(array(0 => 'foo'));
125 $def->replaceArgument(0, 'foo');
127 $def->getArgument(1);