Skip to content

Commit 4ffe63d

Browse files
Wojciech Gorczycafabpot
authored andcommitted
[DI] Fixed wrong factory method in exception
1 parent bc7d977 commit 4ffe63d

File tree

2 files changed

+22
-0
lines changed

2 files changed

+22
-0
lines changed

Compiler/ResolveNamedArgumentsPass.php

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -49,6 +49,7 @@ protected function processValue($value, $isRoot = false)
4949
if (null === $parameters) {
5050
$r = $this->getReflectionMethod($value, $method);
5151
$class = $r instanceof \ReflectionMethod ? $r->class : $this->currentId;
52+
$method = $r->getName();
5253
$parameters = $r->getParameters();
5354
}
5455

Tests/Compiler/ResolveNamedArgumentsPassTest.php

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,9 +16,11 @@
1616
use Symfony\Component\DependencyInjection\ContainerBuilder;
1717
use Symfony\Component\DependencyInjection\Reference;
1818
use Symfony\Component\DependencyInjection\Tests\Fixtures\CaseSensitiveClass;
19+
use Symfony\Component\DependencyInjection\Tests\Fixtures\FactoryDummy;
1920
use Symfony\Component\DependencyInjection\Tests\Fixtures\NamedArgumentsDummy;
2021
use Symfony\Component\DependencyInjection\Tests\Fixtures\NamedArgumentsVariadicsDummy;
2122
use Symfony\Component\DependencyInjection\Tests\Fixtures\SimilarArgumentsDummy;
23+
use Symfony\Component\DependencyInjection\Tests\Fixtures\TestDefinition1;
2224

2325
/**
2426
* @author Kévin Dunglas <dunglas@gmail.com>
@@ -103,6 +105,7 @@ public function testClassNoConstructor()
103105

104106
/**
105107
* @expectedException \Symfony\Component\DependencyInjection\Exception\InvalidArgumentException
108+
* @expectedExceptionMessage Invalid service "Symfony\Component\DependencyInjection\Tests\Fixtures\NamedArgumentsDummy": method "__construct()" has no argument named "$notFound". Check your service definition.
106109
*/
107110
public function testArgumentNotFound()
108111
{
@@ -115,6 +118,24 @@ public function testArgumentNotFound()
115118
$pass->process($container);
116119
}
117120

121+
/**
122+
* @expectedException \Symfony\Component\DependencyInjection\Exception\InvalidArgumentException
123+
* @expectedExceptionMessage Invalid service "Symfony\Component\DependencyInjection\Tests\Fixtures\TestDefinition1": method "Symfony\Component\DependencyInjection\Tests\Fixtures\FactoryDummy::create()" has no argument named "$notFound". Check your service definition.
124+
*/
125+
public function testCorrectMethodReportedInException()
126+
{
127+
$container = new ContainerBuilder();
128+
129+
$container->register(FactoryDummy::class, FactoryDummy::class);
130+
131+
$definition = $container->register(TestDefinition1::class, TestDefinition1::class);
132+
$definition->setFactory(array(FactoryDummy::class, 'create'));
133+
$definition->setArguments(array('$notFound' => '123'));
134+
135+
$pass = new ResolveNamedArgumentsPass();
136+
$pass->process($container);
137+
}
138+
118139
public function testTypedArgument()
119140
{
120141
$container = new ContainerBuilder();

0 commit comments

Comments
 (0)