Skip to content

Commit f4a0443

Browse files
committed
Merge branch '2.8' into 3.1
* 2.8: always check for all fields to be mapped clarify exception when no args are configured [PropertyAccess] Handle interfaces in the invalid argument exception [DI] Fix defaults overriding empty strings in AutowirePass [Debug] Workaround "null" $context [Debug] Remove $context arg from handleError(), preparing for PHP 7.2 [Routing] Fix BC break in AnnotationClassLoader defaults attributes handling Fix tests with ICU 57.1 Fix the condition checking the minimum ICU version
2 parents d05fee2 + 1dfbf6a commit f4a0443

File tree

4 files changed

+35
-2
lines changed

4 files changed

+35
-2
lines changed

Compiler/AutowirePass.php

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -121,8 +121,10 @@ private function completeDefinition($id, Definition $definition)
121121
throw new RuntimeException(sprintf('Unable to autowire argument index %d ($%s) for the service "%s". If this is an object, give it a type-hint. Otherwise, specify this argument\'s value explicitly.', $index, $parameter->name, $id));
122122
}
123123

124-
// specifically pass the default value
125-
$arguments[$index] = $parameter->getDefaultValue();
124+
if (!array_key_exists($index, $arguments)) {
125+
// specifically pass the default value
126+
$arguments[$index] = $parameter->getDefaultValue();
127+
}
126128

127129
continue;
128130
}

Definition.php

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -198,6 +198,10 @@ public function addArgument($argument)
198198
*/
199199
public function replaceArgument($index, $argument)
200200
{
201+
if (0 === count($this->arguments)) {
202+
throw new OutOfBoundsException('Cannot replace arguments if none have been configured yet.');
203+
}
204+
201205
if ($index < 0 || $index > count($this->arguments) - 1) {
202206
throw new OutOfBoundsException(sprintf('The index "%d" is not in the range [0, %d].', $index, count($this->arguments) - 1));
203207
}

Tests/Compiler/AutowirePassTest.php

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -494,6 +494,22 @@ public function testIgnoreServiceWithClassNotExisting()
494494

495495
$this->assertTrue($container->hasDefinition('bar'));
496496
}
497+
498+
public function testEmptyStringIsKept()
499+
{
500+
$container = new ContainerBuilder();
501+
502+
$container->register('a', __NAMESPACE__.'\A');
503+
$container->register('lille', __NAMESPACE__.'\Lille');
504+
$container->register('foo', __NAMESPACE__.'\MultipleArgumentsOptionalScalar')
505+
->setAutowired(true)
506+
->setArguments(array('', ''));
507+
508+
$pass = new AutowirePass();
509+
$pass->process($container);
510+
511+
$this->assertEquals(array(new Reference('a'), '', new Reference('lille')), $container->getDefinition('foo')->getArguments());
512+
}
497513
}
498514

499515
class Foo

Tests/DefinitionTest.php

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

258258
/**
259259
* @expectedException \OutOfBoundsException
260+
* @expectedExceptionMessage The index "1" is not in the range [0, 0].
260261
*/
261262
public function testReplaceArgumentShouldCheckBounds()
262263
{
@@ -266,6 +267,16 @@ public function testReplaceArgumentShouldCheckBounds()
266267
$def->replaceArgument(1, 'bar');
267268
}
268269

270+
/**
271+
* @expectedException \OutOfBoundsException
272+
* @expectedExceptionMessage Cannot replace arguments if none have been configured yet.
273+
*/
274+
public function testReplaceArgumentWithoutExistingArgumentsShouldCheckBounds()
275+
{
276+
$def = new Definition('stdClass');
277+
$def->replaceArgument(0, 'bar');
278+
}
279+
269280
public function testSetGetProperties()
270281
{
271282
$def = new Definition('stdClass');

0 commit comments

Comments
 (0)