Skip to content

Commit

Permalink
[DI] Improve exception message on missing $ of named argument
Browse files Browse the repository at this point in the history
  • Loading branch information
jschaedl authored and fabpot committed Apr 29, 2019
1 parent e9aaaaf commit d0e4499
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,10 @@ protected function processValue($value, $isRoot = false)
$parameters = $r->getParameters();
}

if (isset($key[0]) && '$' !== $key[0] && !class_exists($key)) {
throw new InvalidArgumentException(sprintf('Invalid service "%s": did you forget to add the "$" prefix to argument "%s"?', $this->currentId, $key));
}

if (isset($key[0]) && '$' === $key[0]) {
foreach ($parameters as $j => $p) {
if ($key === '$'.$p->name) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -149,6 +149,21 @@ public function testTypedArgument()
$this->assertEquals([new Reference('foo'), '123'], $definition->getArguments());
}

/**
* @expectedException \Symfony\Component\DependencyInjection\Exception\InvalidArgumentException
* @expectedExceptionMessage Invalid service "Symfony\Component\DependencyInjection\Tests\Fixtures\NamedArgumentsDummy": did you forget to add the "$" prefix to argument "apiKey"?
*/
public function testTypedArgumentWithMissingDollar()
{
$container = new ContainerBuilder();

$definition = $container->register(NamedArgumentsDummy::class, NamedArgumentsDummy::class);
$definition->setArgument('apiKey', '123');

$pass = new ResolveNamedArgumentsPass();
$pass->process($container);
}

public function testResolvesMultipleArgumentsOfTheSameType()
{
$container = new ContainerBuilder();
Expand Down

0 comments on commit d0e4499

Please sign in to comment.