8000 bug #29697 [DI] Fixed wrong factory method in exception (Wojciech Gor… · symfony/symfony@0a3d3d4 · GitHub
[go: up one dir, main page]

Skip to content

Commit 0a3d3d4

Browse files
fabpotxabbuh
authored andcommitted
bug #29697 [DI] Fixed wrong factory method in exception (Wojciech Gorczyca)
This PR was submitted for the 4.2 branch but it was merged into the 4.1 branch instead (closes #29697). Discussion ---------- [DI] Fixed wrong factory method in exception | Q | A | ------------- | --- | Branch? | 4.2 <!-- see below --> | Bug fix? | yes | New feature? | no <!-- don't forget to update src/**/CHANGELOG.md files --> | BC breaks? | no <!-- see https://symfony.com/bc --> | Deprecations? | no <!-- don't forget to update UPGRADE-*.md and src/**/CHANGELOG.md files --> | Tests pass? | yes <!-- please add some, will be required by reviewers --> | Fixed tickets | #29678 <!-- #-prefixed issue number(s), if any --> | License | MIT | Doc PR | n/a <!-- required for new features --> When a service definition with a factory defines invalid arguments, the [resulting exception message ](https://github.com/symfony/symfony/blob/master/src/Symfony/Component/DependencyInjection/Compiler/ResolveNamedArgumentsPass.php#L70)incorrectly specifies the factory constructor instead of the factory method as not having the specified named arguments. <!-- Write a short README entry for your feature/bugfix here (replace this comment block.) This will help people understand your PR and can be used as a start of the Doc PR. Additionally: - Bug fixes must be submitted against the lowest branch where they apply (lowest branches are regularly merged to upper ones so they get the fixes too). - Features and deprecations must be submitted against the master branch. --> Commits ------- 922885c [DI] Fixed wrong factory method in exception
1 parent e38b5d2 commit 0a3d3d4

File tree

2 files changed

+22
-0
lines changed

2 files changed

+22
-0
lines changed

src/Symfony/Component/DependencyInjection/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

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

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,8 +16,10 @@
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\SimilarArgumentsDummy;
22+
use Symfony\Component\DependencyInjection\Tests\Fixtures\TestDefinition1;
2123

2224
/**
2325
* @author Kévin Dunglas <dunglas@gmail.com>
@@ -102,6 +104,7 @@ public function testClassNoConstructor()
102104

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

120+
/**
121+
* @expectedException \Symfony\Component\DependencyInjection\Exception\InvalidArgumentException
122+
* @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.
123+
*/
124+
public function testCorrectMethodReportedInException()
125+
{
126+
$container = new ContainerBuilder();
127+
128+
$container->register(FactoryDummy::class, FactoryDummy::class);
129+
130+
$definition = $container->register(TestDefinition1::class, TestDefinition1::class);
131+
$definition->setFactory(array(FactoryDummy::class, 'create'));
132+
$definition->setArguments(array('$notFound' => '123'));
133+
134+
$pass = new ResolveNamedArgumentsPass();
135+
$pass->process($container);
136+
}
137+
117138
public function testTypedArgument()
118139
{
119140
$container = new ContainerBuilder();

0 commit comments

Comments
 (0)
0