8000 minor #21416 [DependencyInjection] clarify exception when no args are… · symfony/symfony@a35986f · GitHub
[go: up one dir, main page]

Skip to content

Commit a35986f

Browse files
committed
minor #21416 [DependencyInjection] clarify exception when no args are configured (xabbuh)
This PR was merged into the 2.7 branch. Discussion ---------- [DependencyInjection] clarify exception when no args are configured | Q | A | ------------- | --- | Branch? | 2.7 | Bug fix? | yes | New feature? | no | BC breaks? | no | Deprecations? | no | Tests pass? | yes | Fixed tickets | #21412 | License | MIT | Doc PR | Commits ------- 428814b clarify exception when no args are configured
2 parents a6d2420 + 428814b commit a35986f

File tree

2 files changed

+15
-0
lines changed

2 files changed

+15
-0
lines changed

src/Symfony/Component/DependencyInjection/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
}

src/Symfony/Component/DependencyInjection/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)
0