Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[DI] Fixed wrong factory method in exception #29697

Merged
merged 3 commits into from Jan 5, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
Expand Up @@ -155,21 +155,16 @@ public static function getEventDispatchers()

public static function getCallables()
{
$callables = array(
return array(
'callable_1' => 'array_key_exists',
'callable_2' => array('Symfony\\Bundle\\FrameworkBundle\\Tests\\Console\\Descriptor\\CallableClass', 'staticMethod'),
'callable_3' => array(new CallableClass(), 'method'),
'callable_4' => 'Symfony\\Bundle\\FrameworkBundle\\Tests\\Console\\Descriptor\\CallableClass::staticMethod',
'callable_5' => array('Symfony\\Bundle\\FrameworkBundle\\Tests\\Console\\Descriptor\\ExtendedCallableClass', 'parent::staticMethod'),
'callable_6' => function () { return 'Closure'; },
'callable_7' => new CallableClass(),
'callable_from_callable' => \Closure::fromCallable(new CallableClass()),
);

if (\PHP_VERSION_ID >= 70100) {
$callables['callable_from_callable'] = \Closure::fromCallable(new CallableClass());
}

return $callables;
}
}

Expand Down
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
Expand Up @@ -30,21 +30,16 @@ public function testListenerDescription(callable $listener, $expected)

public function provideListenersToDescribe()
{
$listeners = array(
return array(
array(new FooListener(), 'Symfony\Component\EventDispatcher\Tests\Debug\FooListener::__invoke'),
array(array(new FooListener(), 'listen'), 'Symfony\Component\EventDispatcher\Tests\Debug\FooListener::listen'),
array(array('Symfony\Component\EventDispatcher\Tests\Debug\FooListener', 'listenStatic'), 'Symfony\Component\EventDispatcher\Tests\Debug\FooListener::listenStatic'),
array('var_dump', 'var_dump'),
array(function () {}, 'closure'),
array(\Closure::fromCallable(array(new FooListener(), 'listen')), 'Symfony\Component\EventDispatcher\Tests\Debug\FooListener::listen'),
array(\Closure::fromCallable(array('Symfony\Component\EventDispatcher\Tests\Debug\FooListener', 'listenStatic')), 'Symfony\Component\EventDispatcher\Tests\Debug\FooListener::listenStatic'),
array(\Closure::fromCallable(function () {}), 'closure'),
);

if (\PHP_VERSION_ID >= 70100) {
$listeners[] = array(\Closure::fromCallable(array(new FooListener(), 'listen')), 'Symfony\Component\EventDispatcher\Tests\Debug\FooListener::listen');
$listeners[] = array(\Closure::fromCallable(array('Symfony\Component\EventDispatcher\Tests\Debug\FooListener', 'listenStatic')), 'Symfony\Component\EventDispatcher\Tests\Debug\FooListener::listenStatic');
$listeners[] = array(\Closure::fromCallable(function () {}), 'closure');
}

return $listeners;
}
}

Expand Down