bug #21403 [DI] Fix defaults overriding empty strings in AutowirePass (nicolas-grekas)
This PR was merged into the 2.8 branch.
Discussion
----------
[DI] Fix defaults overriding empty strings in AutowirePass
| Q | A
| ------------- | ---
| Branch? | 2.8
| Bug fix? | yes
| New feature? | no
| BC breaks? | no
| Deprecations? | no
| Tests pass? | yes
| Fixed tickets | -
| License | MIT
| Doc PR | -
Commits
-------
89e27240ab
[DI] Fix defaults overriding empty strings in AutowirePass
This commit is contained in:
commit
21f1be16d5
|
@ -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));
|
||||
}
|
||||
|
||||
if (!array_key_exists($index, $arguments)) {
|
||||
// specifically pass the default value
|
||||
$arguments[$index] = $parameter->getDefaultValue();
|
||||
}
|
||||
|
||||
continue;
|
||||
}
|
||||
|
|
|
@ -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
|
||||
|
|
Reference in New Issue