Skip to content

Commit 3eb7fc6

Browse files
committed
Merge branch '3.2'
* 3.2: fixed typo fixed composer.json [HttpKernel] Fix Bundle name regression 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 [FrameworkBundle] Dont wire "annotations.cached_reader" before removing passes [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 9920e8c + 388d368 commit 3eb7fc6

File tree

4 files changed

+31
-3
lines changed

4 files changed

+31
-3
lines changed

Compiler/AutowirePass.php

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -231,8 +231,10 @@ private function autowireMethod(\ReflectionMethod $reflectionMethod, array $argu
231231
return array();
232232
}
233233

234-
// specifically pass the default value
235-
$arguments[$index] = $parameter->getDefaultValue();
234+
if (!array_key_exists($index, $arguments)) {
235+
// specifically pass the default value
236+
$arguments[$index] = $parameter->getDefaultValue();
237+
}
236238

237239
continue;
238240
}

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: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -603,11 +603,22 @@ public function testPartialMethodCalls()
603603
$definition = $container->register('bar', SetterInjection::class);
604604
$definition->setAutowired(true);
605605
$definition->addMethodCall('setDependencies', array(new Reference('foo')));
606+
}
607+
608+
public function testEmptyStringIsKept()
609+
{
610+
$container = new ContainerBuilder();
611+
612+
$container->register('a', __NAMESPACE__.'\A');
613+
$container->register('lille', __NAMESPACE__.'\Lille');
614+
$container->register('foo', __NAMESPACE__.'\MultipleArgumentsOptionalScalar')
615+
->setAutowired(true)
616+
->setArguments(array('', ''));
606617

607618
$pass = new AutowirePass();
608619
$pass->process($container);
609620

610-
$this->assertEquals(array(array('setDependencies', array(new Reference('foo'), new Reference('a')))), $container->getDefinition('bar')->getMethodCalls());
621+
$this->assertEquals(array(new Reference('a'), '', new Reference('lille')), $container->getDefinition('foo')->getArguments());
611622
}
612623
}
613624

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)