From 7a132fe1561efb31d861b5bfbc69fa6583a3f3e2 Mon Sep 17 00:00:00 2001 From: Christian Flothmann Date: Fri, 4 Jan 2019 16:09:47 +0100 Subject: [PATCH 1/2] remove no longer needed PHP version checks --- .../Tests/Console/Descriptor/ObjectsProvider.php | 9 ++------- .../Tests/Debug/WrappedListenerTest.php | 13 ++++--------- 2 files changed, 6 insertions(+), 16 deletions(-) diff --git a/src/Symfony/Bundle/FrameworkBundle/Tests/Console/Descriptor/ObjectsProvider.php b/src/Symfony/Bundle/FrameworkBundle/Tests/Console/Descriptor/ObjectsProvider.php index 12e81898bf5f..7cb887684fea 100644 --- a/src/Symfony/Bundle/FrameworkBundle/Tests/Console/Descriptor/ObjectsProvider.php +++ b/src/Symfony/Bundle/FrameworkBundle/Tests/Console/Descriptor/ObjectsProvider.php @@ -155,7 +155,7 @@ 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'), @@ -163,13 +163,8 @@ public static function getCallables() '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; } } diff --git a/src/Symfony/Component/EventDispatcher/Tests/Debug/WrappedListenerTest.php b/src/Symfony/Component/EventDispatcher/Tests/Debug/WrappedListenerTest.php index f743f148d2d2..3847a1553c76 100644 --- a/src/Symfony/Component/EventDispatcher/Tests/Debug/WrappedListenerTest.php +++ b/src/Symfony/Component/EventDispatcher/Tests/Debug/WrappedListenerTest.php @@ -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; } } From 922885c89243fd1a796b1fe9daa63f428fdd92cb Mon Sep 17 00:00:00 2001 From: Wojciech Gorczyca Date: Thu, 27 Dec 2018 13:08:49 +0100 Subject: [PATCH 2/2] [DI] Fixed wrong factory method in exception --- .../Compiler/ResolveNamedArgumentsPass.php | 1 + .../ResolveNamedArgumentsPassTest.php | 21 +++++++++++++++++++ 2 files changed, 22 insertions(+) diff --git a/src/Symfony/Component/DependencyInjection/Compiler/ResolveNamedArgumentsPass.php b/src/Symfony/Component/DependencyInjection/Compiler/ResolveNamedArgumentsPass.php index f9431b21d890..b5b832c83f0b 100644 --- a/src/Symfony/Component/DependencyInjection/Compiler/ResolveNamedArgumentsPass.php +++ b/src/Symfony/Component/DependencyInjection/Compiler/ResolveNamedArgumentsPass.php @@ -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(); } diff --git a/src/Symfony/Component/DependencyInjection/Tests/Compiler/ResolveNamedArgumentsPassTest.php b/src/Symfony/Component/DependencyInjection/Tests/Compiler/ResolveNamedArgumentsPassTest.php index 4665ee96f5f3..b900c41a8c4f 100644 --- a/src/Symfony/Component/DependencyInjection/Tests/Compiler/ResolveNamedArgumentsPassTest.php +++ b/src/Symfony/Component/DependencyInjection/Tests/Compiler/ResolveNamedArgumentsPassTest.php @@ -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 @@ -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() { @@ -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();