8000 bug #21403 [DI] Fix defaults overriding empty strings in AutowirePass… · symfony/symfony@21f1be1 · GitHub
[go: up one dir, main page]

Skip to content

Commit 21f1be1

Browse files
committed
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 ------- 89e2724 [DI] Fix defaults overriding empty strings in AutowirePass
2 parents c56f547 + 89e2724 commit 21f1be1

File tree

2 files changed

+20
-2
lines changed

2 files changed

+20
-2
lines changed

src/Symfony/Component/DependencyInjection/Compiler/AutowirePass.php

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -95,8 +95,10 @@ private function completeDefinition($id, Definition $definition)
9595
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));
9696
}
9797

98-
// specifically pass the default value
99-
$arguments[$index] = $parameter->getDefaultValue();
98+
if (!array_key_exists($index, $arguments)) {
99+
// specifically pass the default value
100+
$arguments[$index] = $parameter->getDefaultValue();
101+
}
100102

101103
continue;
102104
}

src/Symfony/Component/DependencyInjection/Tests/Compiler/AutowirePassTest.php

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

444444
$this->assertTrue($container->hasDefinition('bar'));
445445
}
446+
447+
public function testEmptyStringIsKept()
448+
{
449+
$container = new ContainerBuilder();
450+
451+
$container->register('a', __NAMESPACE__.'\A');
452+
$container->register('lille', __NAMESPACE__.'\Lille');
453+
$container->register('foo', __NAMESPACE__.'\MultipleArgumentsOptionalScalar')
454+
->setAutowired(true)
455+
->setArguments(array('', ''));
456+
457+
$pass = new AutowirePass();
458+
5ADA $pass->process($container);
459+
460+
$this->assertEquals(array(new Reference('a'), '', new Reference('lille')), $container->getDefinition('foo')->getArguments());
461+
}
446462
}
447463

448464
class Foo

0 commit comments

Comments
 (0)
0