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;
20 class DefinitionDecoratorTest extends TestCase
22 public function testConstructor()
24 $def = new DefinitionDecorator('foo');
26 $this->assertEquals('foo', $def->getParent());
27 $this->assertEquals(array(), $def->getChanges());
31 * @dataProvider getPropertyTests
33 public function testSetProperty($property, $changeKey)
35 $def = new DefinitionDecorator('foo');
37 $getter = 'get'.ucfirst($property);
38 $setter = 'set'.ucfirst($property);
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());
46 public function getPropertyTests()
49 array('class', 'class'),
50 array('factory', 'factory'),
51 array('configurator', 'configurator'),
52 array('file', 'file'),
56 public function testSetPublic()
58 $def = new DefinitionDecorator('foo');
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());
66 public function testSetLazy()
68 $def = new DefinitionDecorator('foo');
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());
76 public function testSetAutowired()
78 $def = new DefinitionDecorator('foo');
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());
86 public function testSetArgument()
88 $def = new DefinitionDecorator('foo');
90 $this->assertEquals(array(), $def->getArguments());
91 $this->assertSame($def, $def->replaceArgument(0, 'foo'));
92 $this->assertEquals(array('index_0' => 'foo'), $def->getArguments());
96 * @expectedException \InvalidArgumentException
98 public function testReplaceArgumentShouldRequireIntegerIndex()
100 $def = new DefinitionDecorator('foo');
102 $def->replaceArgument('0', 'foo');
105 public function testReplaceArgument()
107 $def = new DefinitionDecorator('foo');
109 $def->setArguments(array(0 => 'foo', 1 => 'bar'));
110 $this->assertEquals('foo', $def->getArgument(0));
111 $this->assertEquals('bar', $def->getArgument(1));
113 $this->assertSame($def, $def->replaceArgument(1, 'baz'));
114 $this->assertEquals('foo', $def->getArgument(0));
115 $this->assertEquals('baz', $def->getArgument(1));
117 $this->assertEquals(array(0 => 'foo', 1 => 'bar', 'index_1' => 'baz'), $def->getArguments());
121 * @expectedException \OutOfBoundsException
123 public function testGetArgumentShouldCheckBounds()
125 $def = new DefinitionDecorator('foo');
127 $def->setArguments(array(0 => 'foo'));
128 $def->replaceArgument(0, 'foo');
130 $def->getArgument(1);