Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings

Commit 66f6e8e

Browse filesBrowse files
author
Amrouche Hamza
committed
add tests
1 parent 9b8397b commit 66f6e8e
Copy full SHA for 66f6e8e

File tree

3 files changed

+42
-1
lines changed
Filter options

3 files changed

+42
-1
lines changed

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

Copy file name to clipboardExpand all lines: src/Symfony/Component/DependencyInjection/Compiler/AutowirePass.php
+9-1Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -158,7 +158,15 @@ private function autowireCalls(\ReflectionClass $reflectionClass, bool $isRoot):
158158
if ($method instanceof \ReflectionFunctionAbstract) {
159159
$reflectionMethod = $method;
160160
} else {
161-
$reflectionMethod = $this->getReflectionMethod(new Definition($reflectionClass->name), $method);
161+
$definition = new Definition($reflectionClass->name);
162+
try {
163+
$reflectionMethod = $this->getReflectionMethod($definition, $method);
164+
} catch (RuntimeException $e) {
165+
if ($definition->getFactory()) {
166+
continue;
167+
}
168+
throw $e;
169+
}
162170
}
163171

164172
$arguments = $this->autowireMethod($reflectionMethod, $arguments);

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

Copy file name to clipboardExpand all lines: src/Symfony/Component/DependencyInjection/Tests/Compiler/AutowirePassTest.php
+13Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,7 @@
2626
use Symfony\Component\DependencyInjection\Reference;
2727
use Symfony\Component\DependencyInjection\Tests\Fixtures\includes\FooVariadic;
2828
use Symfony\Component\DependencyInjection\TypedReference;
29+
use Symfony\Component\HttpKernel\HttpKernelInterface;
2930

3031
require_once __DIR__.'/../Fixtures/includes/autowiring_classes.php';
3132

@@ -545,6 +546,18 @@ public function testSetterInjection()
545546
);
546547
}
547548

549+
public function testWithNonExistingSetterAndAutowiring()
550+
{
551+
$container = new ContainerBuilder();
552+
553+
$definition = $container->register(HttpKernelInterface::class, HttpKernelInterface::class)->setAutowired(true);
554+
$definition->addMethodCall('setLogger');
555+
$this->expectException(RuntimeException::class);
556+
(new ResolveClassPass())->process($container);
557+
(new AutowireRequiredMethodsPass())->process($container);
558+
(new AutowirePass())->process($container);
559+
}
560+
548561
public function testExplicitMethodInjection()
549562
{
550563
$container = new ContainerBuilder();

‎src/Symfony/Component/DependencyInjection/Tests/Compiler/ResolveBindingsPassTest.php

Copy file name to clipboardExpand all lines: src/Symfony/Component/DependencyInjection/Tests/Compiler/ResolveBindingsPassTest.php
+20Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,11 +16,14 @@
1616
use Symfony\Component\DependencyInjection\Compiler\AutowireRequiredMethodsPass;
1717
use Symfony\Component\DependencyInjection\Compiler\ResolveBindingsPass;
1818
use Symfony\Component\DependencyInjection\ContainerBuilder;
19+
use Symfony\Component\DependencyInjection\Definition;
20+
use Symfony\Component\DependencyInjection\Exception\RuntimeException;
1921
use Symfony\Component\DependencyInjection\Reference;
2022
use Symfony\Component\DependencyInjection\Tests\Fixtures\CaseSensitiveClass;
2123
use Symfony\Component\DependencyInjection\Tests\Fixtures\NamedArgumentsDummy;
2224
use Symfony\Component\DependencyInjection\Tests\Fixtures\ParentNotExists;
2325
use Symfony\Component\DependencyInjection\TypedReference;
26+
use Symfony\Component\HttpKernel\HttpKernelInterface;
2427

2528
require_once __DIR__.'/../Fixtures/includes/autowiring_classes.php';
2629

@@ -112,6 +115,23 @@ public function testScalarSetter()
112115
$this->assertEquals([['setDefaultLocale', ['fr']]], $definition->getMethodCalls());
113116
}
114117

118+
public function testWithNonExistingSetterAndBinding()
119+
{
120+
$container = new ContainerBuilder();
121+
122+
$bindings = [
123+
'$c' => (new Definition('logger'))->setFactory('logger'),
124+
];
125+
126+
$definition = $container->register(HttpKernelInterface::class, HttpKernelInterface::class);
127+
$definition->addMethodCall('setLogger');
128+
$definition->setBindings($bindings);
129+
$this->expectException(RuntimeException::class);
130+
131+
$pass = new ResolveBindingsPass();
132+
$pass->process($container);
133+
}
134+
115135
public function testTupleBinding()
116136
{
117137
$container = new ContainerBuilder();

0 commit comments

Comments
0 (0)
Morty Proxy This is a proxified and sanitized view of the page, visit original site.