clarify exception when no args are configured

This commit is contained in:
Christian Flothmann 2017-01-26 11:48:39 +01:00
parent a6d2420f00
commit 428814b25d
2 changed files with 15 additions and 0 deletions

View File

@ -302,6 +302,10 @@ class Definition
*/
public function replaceArgument($index, $argument)
{
if (0 === count($this->arguments)) {
throw new OutOfBoundsException('Cannot replace arguments if none have been configured yet.');
}
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));
}

View File

@ -232,6 +232,7 @@ class DefinitionTest extends \PHPUnit_Framework_TestCase
/**
* @expectedException \OutOfBoundsException
* @expectedExceptionMessage The index "1" is not in the range [0, 0].
*/
public function testReplaceArgumentShouldCheckBounds()
{
@ -241,6 +242,16 @@ class DefinitionTest extends \PHPUnit_Framework_TestCase
$def->replaceArgument(1, 'bar');
}
/**
* @expectedException \OutOfBoundsException
* @expectedExceptionMessage Cannot replace arguments if none have been configured yet.
*/
public function testReplaceArgumentWithoutExistingArgumentsShouldCheckBounds()
{
$def = new Definition('stdClass');
$def->replaceArgument(0, 'bar');
}
public function testSetGetProperties()
{
$def = new Definition('stdClass');