adds setArgument to Definition

This commit is contained in:
Johannes M. Schmitt 2011-01-18 18:53:11 +01:00 committed by Fabien Potencier
parent bdd2c91abd
commit 84fa4b50db
2 changed files with 40 additions and 0 deletions

View File

@ -145,6 +145,25 @@ class Definition
return $this;
}
/**
* Sets a specific argument
*
* @param integer $index
* @param mixed $argument
*
* @return Definition The current instance
*/
public function setArgument($index, $argument)
{
if ($index < 0 || $index > count($this->arguments) - 1) {
throw new \OutOfBoundsException(sprintf('The index "%d" is not in the range [0, %d].', $index, count($this->arguments) - 1));
}
$this->arguments[$index] = $argument;
return $this;
}
/**
* Gets the arguments to pass to the service constructor/factory method.
*

View File

@ -167,4 +167,25 @@ class DefinitionTest extends \PHPUnit_Framework_TestCase
'bar' => array(array('bar' => 'bar')),
), '->getTags() returns all tags');
}
/**
* @covers Symfony\Component\DependencyInjection\Definition::setArgument
*/
public function testSetArgument()
{
$def = new Definition('stdClass');
$def->addArgument('foo');
$this->assertSame(array('foo'), $def->getArguments());
$this->assertSame($def, $def->setArgument(0, 'moo'));
$this->assertSame(array('moo'), $def->getArguments());
$def->addArgument('moo');
$def
->setArgument(0, 'foo')
->setArgument(1, 'bar')
;
$this->assertSame(array('foo', 'bar'), $def->getArguments());
}
}