Skip to content

Commit 0dd7e22

Browse files
committed
clarify exception when no args are configured
1 parent 75f0e1e commit 0dd7e22

File tree

2 files changed

+15
-0
lines changed

2 files changed

+15
-0
lines changed

Definition.php

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -302,6 +302,10 @@ public function addArgument($argument)
302302
*/
303303
public function replaceArgument($index, $argument)
304304
{
305+
if (0 === count($this->arguments)) {
306+
throw new OutOfBoundsException('Cannot replace arguments if none have been configured yet.');
307+
}
308+
305309
if ($index < 0 || $index > count($this->arguments) - 1) {
306310
throw new OutOfBoundsException(sprintf('The index "%d" is not in the range [0, %d].', $index, count($this->arguments) - 1));
307311
}

Tests/DefinitionTest.php

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -232,6 +232,7 @@ public function testGetArgumentShouldCheckBounds()
232232

233233
/**
234234
* @expectedException \OutOfBoundsException
235+
* @expectedExceptionMessage The index "1" is not in the range [0, 0].
235236
*/
236237
public function testReplaceArgumentShouldCheckBounds()
237238
{
@@ -241,6 +242,16 @@ public function testReplaceArgumentShouldCheckBounds()
241242
$def->replaceArgument(1, 'bar');
242243
}
243244

245+
/**
246+
* @expectedException \OutOfBoundsException
247+
* @expectedExceptionMessage Cannot replace arguments if none have been configured yet.
248+
*/
249+
public function testReplaceArgumentWithoutExistingArgumentsShouldCheckBounds()
250+
{
251+
$def = new Definition('stdClass');
252+
$def->replaceArgument(0, 'bar');
253+
}
254+
244255
public function testSetGetProperties()
245256
{
246257
$def = new Definition('stdClass');

0 commit comments

Comments
 (0)