Skip to content

Commit

Permalink
[DI] Fixed wrong factory method in exception
Browse files Browse the repository at this point in the history
  • Loading branch information
Wojciech Gorczyca authored and fabpot committed Jan 5, 2019
1 parent 34c8a8b commit 922885c
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 0 deletions.
Expand Up @@ -49,6 +49,7 @@ protected function processValue($value, $isRoot = false)
if (null === $parameters) {
$r = $this->getReflectionMethod($value, $method);
$class = $r instanceof \ReflectionMethod ? $r->class : $this->currentId;
$method = $r->getName();
$parameters = $r->getParameters();
}

Expand Down
Expand Up @@ -16,9 +16,11 @@
use Symfony\Component\DependencyInjection\ContainerBuilder;
use Symfony\Component\DependencyInjection\Reference;
use Symfony\Component\DependencyInjection\Tests\Fixtures\CaseSensitiveClass;
use Symfony\Component\DependencyInjection\Tests\Fixtures\FactoryDummy;
use Symfony\Component\DependencyInjection\Tests\Fixtures\NamedArgumentsDummy;
use Symfony\Component\DependencyInjection\Tests\Fixtures\NamedArgumentsVariadicsDummy;
use Symfony\Component\DependencyInjection\Tests\Fixtures\SimilarArgumentsDummy;
use Symfony\Component\DependencyInjection\Tests\Fixtures\TestDefinition1;

/**
* @author Kévin Dunglas <dunglas@gmail.com>
Expand Down Expand Up @@ -103,6 +105,7 @@ public function testClassNoConstructor()

/**
* @expectedException \Symfony\Component\DependencyInjection\Exception\InvalidArgumentException
* @expectedExceptionMessage Invalid service "Symfony\Component\DependencyInjection\Tests\Fixtures\NamedArgumentsDummy": method "__construct()" has no argument named "$notFound". Check your service definition.
*/
public function testArgumentNotFound()
{
Expand All @@ -115,6 +118,24 @@ public function testArgumentNotFound()
$pass->process($container);
}

/**
* @expectedException \Symfony\Component\DependencyInjection\Exception\InvalidArgumentException
* @expectedExceptionMessage Invalid service "Symfony\Component\DependencyInjection\Tests\Fixtures\TestDefinition1": method "Symfony\Component\DependencyInjection\Tests\Fixtures\FactoryDummy::create()" has no argument named "$notFound". Check your service definition.
*/
public function testCorrectMethodReportedInException()
{
$container = new ContainerBuilder();

$container->register(FactoryDummy::class, FactoryDummy::class);

$definition = $container->register(TestDefinition1::class, TestDefinition1::class);
$definition->setFactory(array(FactoryDummy::class, 'create'));
$definition->setArguments(array('$notFound' => '123'));

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

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

0 comments on commit 922885c

Please sign in to comment.