8000 add tests · symfony/symfony@ad4c735 · GitHub
[go: up one dir, main page]

Skip to content

Commit ad4c735

Browse files
author
Amrouche Hamza
committed
add tests
1 parent 9b8397b commit ad4c735

File tree

3 files changed

+44
-2
lines changed

3 files changed

+44
-2
lines changed

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

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -158,8 +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);
162-
}
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+
} }
163170

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

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

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,14 +18,17 @@
1818
use Symfony\Component\DependencyInjection\Compiler\AutowirePass;
1919
use Symfony\Component\DependencyInjection\Compiler\AutowireRequiredMethodsPass;
2020
use Symfony\Component\DependencyInjection\Compiler\DecoratorServicePass;
21+
use Symfony\Component\DependencyInjection\Compiler\ResolveBindingsPass;
2122
use Symfony\Component\DependencyInjection\Compiler\ResolveClassPass;
2223
use Symfony\Component\DependencyInjection\ContainerBuilder;
24+
use Symfony\Component\DependencyInjection\Definition;
2325
use Symfony\Component\DependencyInjection\Exception\AutowiringFailedException;
2426
use Symfony\Component\DependencyInjection\Excep 10000 tion\RuntimeException;
2527
use Symfony\Component\DependencyInjection\Loader\XmlFileLoader;
2628
use Symfony\Component\DependencyInjection\Reference;
2729
use Symfony\Component\DependencyInjection\Tests\Fixtures\includes\FooVariadic;
2830
use Symfony\Component\DependencyInjection\TypedReference;
31+
use Symfony\Component\HttpKernel\HttpKernelInterface;
2932

3033
require_once __DIR__.'/../Fixtures/includes/autowiring_classes.php';
3134

@@ -545,6 +548,18 @@ public function testSetterInjection()
545548
);
546549
}
547550

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

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

Lines 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