Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit 19ab889

Browse files
bug #27834 [DI] Don't show internal service id on binding errors (nicolas-grekas)
This PR was merged into the 3.4 branch. Discussion ---------- [DI] Don't show internal service id on binding errors | Q | A | ------------- | --- | Branch? | 3.4 | Bug fix? | yes | New feature? | no | BC breaks? | no | Deprecations? | no | Tests pass? | yes | Fixed tickets | - | License | MIT | Doc PR | - Will throw Unused binding "$variableName" in service "App\Twig\AppExtension". instead of the current Unused binding "$variableName" in service ".abstract.instanceof.App\Twig\AppExtension". Commits ------- 61f005a [DI] Don't show internal service id on binding errors
2 parents 771c22b + 61f005a commit 19ab889

File tree

2 files changed

+18
-1
lines changed

2 files changed

+18
-1
lines changed

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

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -117,9 +117,11 @@ private function processDefinition(ContainerBuilder $container, $id, Definition
117117
}
118118
}
119119

120+
$definition->setBindings($bindings);
121+
120122
// reset fields with "merge" behavior
121123
$abstract
122-
->setBindings($bindings)
124+
->setBindings(array())
123125
->setArguments(array())
124126
->setMethodCalls(array())
125127
->setDecoratedService(null)

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

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@
1212
namespace Symfony\Component\DependencyInjection\Tests\Compiler;
1313

1414
use PHPUnit\Framework\TestCase;
15+
use Symfony\Component\DependencyInjection\Argument\BoundArgument;
1516
use Symfony\Component\DependencyInjection\ChildDefinition;
1617
use Symfony\Component\DependencyInjection\Compiler\ResolveInstanceofConditionalsPass;
1718
use Symfony\Component\DependencyInjection\Compiler\ResolveChildDefinitionsPass;
@@ -250,4 +251,18 @@ public function testMergeReset()
250251
$this->assertEmpty($abstract->getTags());
251252
$this->assertTrue($abstract->isAbstract());
252253
}
254+
255+
public function testBindings()
256+
{
257+
$container = new ContainerBuilder();
258+
$def = $container->register('foo', self::class)->setBindings(array('$toto' => 123));
259+
$def->setInstanceofConditionals(array(parent::class => new ChildDefinition('')));
260+
261+
(new ResolveInstanceofConditionalsPass())->process($container);
262+
263+
$bindings = $container->getDefinition('foo')->getBindings();
264+
$this->assertSame(array('$toto'), array_keys($bindings));
265+
$this->assertInstanceOf(BoundArgument::class, $bindings['$toto']);
266+
$this->assertSame(123, $bindings['$toto']->getValues()[0]);
267+
}
253268
}

0 commit comments

Comments
 (0)