Skip to content

Commit 8ddf737

Browse files
Merge branch '4.3' into 4.4
* 4.3: Do not include hidden commands in suggested alternatives [DependencyInjection] Fix wrong exception when service is synthetic
2 parents 506db25 + 353d1c8 commit 8ddf737

File tree

3 files changed

+28
-3
lines changed

3 files changed

+28
-3
lines changed

Compiler/AbstractRecursivePass.php

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -113,6 +113,10 @@ protected function processValue($value, $isRoot = false)
113113
*/
114114
protected function getConstructor(Definition $definition, $required)
115115
{
116+
if ($definition->isSynthetic()) {
117+
return null;
118+
}
119+
116120
if (\is_string($factory = $definition->getFactory())) {
117121
if (!\function_exists($factory)) {
118122
throw new RuntimeException(sprintf('Invalid service "%s": function "%s" does not exist.', $this->currentId, $factory));

Tests/Compiler/AutowirePassTest.php

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -568,12 +568,10 @@ public function testSetterInjection()
568568
);
569569
}
570570

571-
/**
572-
* @exceptedExceptionMessage Invalid service "Symfony\Component\DependencyInjection\Tests\Fixtures\NamedArgumentsDummy": method "setLogger()" does not exist.
573-
*/
574571
public function testWithNonExistingSetterAndAutowiring()
575572
{
576573
$this->expectException(RuntimeException::class);
574+
$this->expectExceptionMessage('Invalid service "Symfony\Component\DependencyInjection\Tests\Fixtures\CaseSensitiveClass": method "setLogger()" does not exist.');
577575
$container = new ContainerBuilder();
578576

579577
$definition = $container->register(CaseSensitiveClass::class, CaseSensitiveClass::class)->setAutowired(true);

Tests/Compiler/ResolveBindingsPassTest.php

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,9 +15,11 @@
1515
use Symfony\Component\DependencyInjection\Argument\BoundArgument;
1616
use Symfony\Component\DependencyInjection\Argument\TaggedIteratorArgument;
1717
use Symfony\Component\DependencyInjection\Compiler\AutowireRequiredMethodsPass;
18+
use Symfony\Component\DependencyInjection\Compiler\DefinitionErrorExceptionPass;
1819
use Symfony\Component\DependencyInjection\Compiler\ResolveBindingsPass;
1920
use Symfony\Component\DependencyInjection\ContainerBuilder;
2021
use Symfony\Component\DependencyInjection\Definition;
22+
use Symfony\Component\DependencyInjection\Exception\InvalidArgumentException;
2123
use Symfony\Component\DependencyInjection\Reference;
2224
use Symfony\Component\DependencyInjection\Tests\Fixtures\CaseSensitiveClass;
2325
use Symfony\Component\DependencyInjection\Tests\Fixtures\NamedArgumentsDummy;
@@ -131,4 +133,25 @@ public function testWithNonExistingSetterAndBinding()
131133
$pass = new ResolveBindingsPass();
132134
$pass->process($container);
133135
}
136+
137+
public function testSyntheticServiceWithBind()
138+
{
139+
$container = new ContainerBuilder();
140+
$argument = new BoundArgument('bar');
141+
142+
$container->register('foo', 'stdClass')
143+
->addArgument(new Reference('synthetic.service'));
144+
145+
$container->register('synthetic.service')
146+
->setSynthetic(true)
147+
->setBindings(['$apiKey' => $argument]);
148+
149+
$container->register(NamedArgumentsDummy::class, NamedArgumentsDummy::class)
150+
->setBindings(['$apiKey' => $argument]);
151+
152+
(new ResolveBindingsPass())->process($container);
153+
(new DefinitionErrorExceptionPass())->process($container);
154+
155+
$this->assertSame([1 => 'bar'], $container->getDefinition(NamedArgumentsDummy::class)->getArguments());
156+
}
134157
}

0 commit comments

Comments
 (0)