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
-------

61f005af36 [DI] Don't show internal service id on binding errors
This commit is contained in:
Nicolas Grekas 2018-07-04 17:42:48 +02:00
commit 19ab889ed6
2 changed files with 18 additions and 1 deletions

View File

@ -117,9 +117,11 @@ class ResolveInstanceofConditionalsPass implements CompilerPassInterface
}
}
$definition->setBindings($bindings);
// reset fields with "merge" behavior
$abstract
->setBindings($bindings)
->setBindings(array())
->setArguments(array())
->setMethodCalls(array())
->setDecoratedService(null)

View File

@ -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 @@ class ResolveInstanceofConditionalsPassTest extends TestCase
$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]);
}
}