[DI] Fix defaults overriding empty strings in AutowirePass

This commit is contained in:
Nicolas Grekas 2017-01-25 13:10:29 +01:00
parent c56f547c7d
commit 89e27240ab
2 changed files with 20 additions and 2 deletions

View File

@ -95,8 +95,10 @@ class AutowirePass implements CompilerPassInterface
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));
}
// specifically pass the default value
$arguments[$index] = $parameter->getDefaultValue();
if (!array_key_exists($index, $arguments)) {
// specifically pass the default value
$arguments[$index] = $parameter->getDefaultValue();
}
continue;
}

View File

@ -443,6 +443,22 @@ class AutowirePassTest extends \PHPUnit_Framework_TestCase
$this->assertTrue($container->hasDefinition('bar'));
}
public function testEmptyStringIsKept()
{
$container = new ContainerBuilder();
$container->register('a', __NAMESPACE__.'\A');
$container->register('lille', __NAMESPACE__.'\Lille');
$container->register('foo', __NAMESPACE__.'\MultipleArgumentsOptionalScalar')
->setAutowired(true)
->setArguments(array('', ''));
$pass = new AutowirePass();
$pass->process($container);
$this->assertEquals(array(new Reference('a'), '', new Reference('lille')), $container->getDefinition('foo')->getArguments());
}
}
class Foo