Skip to content

Commit

Permalink
bug #27834 [DI] Don't show internal service id on binding errors (nic…
Browse files Browse the repository at this point in the history
…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 19ab889
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 1 deletion.
Expand Up @@ -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)
Expand Down
Expand Up @@ -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;
Expand Down Expand Up @@ -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.