Permalink
Browse files

bug #27834 [DI] Don't show internal service id on binding errors (nic…

…olas-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
  • Loading branch information...
nicolas-grekas committed Jul 4, 2018
2 parents 771c22b + 61f005a commit 19ab889ed62d48589311e247b3c2e90f840a53bf
@@ -117,9 +117,11 @@ private function processDefinition(ContainerBuilder $container, $id, Definition
}
}
$definition->setBindings($bindings);
// reset fields with "merge" behavior
$abstract
->setBindings($bindings)
->setBindings(array())
->setArguments(array())
->setMethodCalls(array())
->setDecoratedService(null)
@@ -12,6 +12,7 @@
namespace Symfony\Component\DependencyInjection\Tests\Compiler;
use PHPUnit\Framework\TestCase;
use Symfony\Component\DependencyInjection\Argument\BoundArgument;
use Symfony\Component\DependencyInjection\ChildDefinition;
use Symfony\Component\DependencyInjection\Compiler\ResolveInstanceofConditionalsPass;
use Symfony\Component\DependencyInjection\Compiler\ResolveChildDefinitionsPass;
@@ -250,4 +251,18 @@ public function testMergeReset()
$this->assertEmpty($abstract->getTags());
$this->assertTrue($abstract->isAbstract());
}
public function testBindings()
{
$container = new ContainerBuilder();
$def = $container->register('foo', self::class)->setBindings(array('$toto' => 123));
$def->setInstanceofConditionals(array(parent::class => new ChildDefinition('')));
(new ResolveInstanceofConditionalsPass())->process($container);
$bindings = $container->getDefinition('foo')->getBindings();
$this->assertSame(array('$toto'), array_keys($bindings));
$this->assertInstanceOf(BoundArgument::class, $bindings['$toto']);
$this->assertSame(123, $bindings['$toto']->getValues()[0]);
}
}

0 comments on commit 19ab889

Please sign in to comment.