Skip to content

Commit 353d1c8

Browse files
Merge branch '3.4' into 4.3
* 3.4: Do not include hidden commands in suggested alternatives [DependencyInjection] Fix wrong exception when service is synthetic
2 parents e85c74d + 9cf8179 commit 353d1c8

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
@@ -14,9 +14,11 @@
1414
use PHPUnit\Framework\TestCase;
1515
use Symfony\Component\DependencyInjection\Argument\BoundArgument;
1616
use Symfony\Component\DependencyInjection\Compiler\AutowireRequiredMethodsPass;
17+
use Symfony\Component\DependencyInjection\Compiler\DefinitionErrorExceptionPass;
1718
use Symfony\Component\DependencyInjection\Compiler\ResolveBindingsPass;
1819
use Symfony\Component\DependencyInjection\ContainerBuilder;
1920
use Symfony\Component\DependencyInjection\Definition;
21+
use Symfony\Component\DependencyInjection\Exception\InvalidArgumentException;
2022
use Symfony\Component\DependencyInjection\Reference;
2123
use Symfony\Component\DependencyInjection\Tests\Fixtures\CaseSensitiveClass;
2224
use Symfony\Component\DependencyInjection\Tests\Fixtures\NamedArgumentsDummy;
@@ -127,4 +129,25 @@ public function testWithNonExistingSetterAndBinding()
127129
$pass = new ResolveBindingsPass();
128130
$pass->process($container);
129131
}
132+
133+
public function testSyntheticServiceWithBind()
134+
{
135+
$container = new ContainerBuilder();
136+
$argument = new BoundArgument('bar');
137+
138+
$container->register('foo', 'stdClass')
139+
->addArgument(new Reference('synthetic.service'));
140+
141+
$container->register('synthetic.service')
142+
->setSynthetic(true)
143+
->setBindings(['$apiKey' => $argument]);
144+
145+
$container->register(NamedArgumentsDummy::class, NamedArgumentsDummy::class)
146+
->setBindings(['$apiKey' => $argument]);
147+
148+
(new ResolveBindingsPass())->process($container);
149+
(new DefinitionErrorExceptionPass())->process($container);
150+
151+
$this->assertSame([1 => 'bar'], $container->getDefinition(NamedArgumentsDummy::class)->getArguments());
152+
}
130153
}

0 commit comments

Comments
 (0)