From 860164ee7e0573771d35fd7631fa95e23f29124e Mon Sep 17 00:00:00 2001 From: Alessandro Chitolina Date: Fri, 21 Jun 2019 11:39:24 +0200 Subject: [PATCH] [DebugBundle] fix register ReflectionCaster::unsetClosureFileInfo caster in var cloner service --- .../DependencyInjection/DebugExtension.php | 5 +-- .../DebugExtensionTest.php | 34 +++++++++++++++++++ 2 files changed, 37 insertions(+), 2 deletions(-) diff --git a/src/Symfony/Bundle/DebugBundle/DependencyInjection/DebugExtension.php b/src/Symfony/Bundle/DebugBundle/DependencyInjection/DebugExtension.php index a183e82cf8..8309db19ec 100644 --- a/src/Symfony/Bundle/DebugBundle/DependencyInjection/DebugExtension.php +++ b/src/Symfony/Bundle/DebugBundle/DependencyInjection/DebugExtension.php @@ -17,6 +17,7 @@ use Symfony\Component\DependencyInjection\ContainerBuilder; use Symfony\Component\DependencyInjection\Extension\Extension; use Symfony\Component\DependencyInjection\Loader\XmlFileLoader; use Symfony\Component\DependencyInjection\Reference; +use Symfony\Component\VarDumper\Caster\ReflectionCaster; use Symfony\Component\VarDumper\Dumper\CliDumper; use Symfony\Component\VarDumper\Dumper\HtmlDumper; @@ -43,9 +44,9 @@ class DebugExtension extends Extension ->addMethodCall('setMinDepth', [$config['min_depth']]) ->addMethodCall('setMaxString', [$config['max_string_length']]); - if (method_exists(ReflectionClass::class, 'unsetClosureFileInfo')) { + if (method_exists(ReflectionCaster::class, 'unsetClosureFileInfo')) { $container->getDefinition('var_dumper.cloner') - ->addMethodCall('addCasters', ReflectionClass::UNSET_CLOSURE_FILE_INFO); + ->addMethodCall('addCasters', [ReflectionCaster::UNSET_CLOSURE_FILE_INFO]); } if (method_exists(HtmlDumper::class, 'setTheme') && 'dark' !== $config['theme']) { diff --git a/src/Symfony/Bundle/DebugBundle/Tests/DependencyInjection/DebugExtensionTest.php b/src/Symfony/Bundle/DebugBundle/Tests/DependencyInjection/DebugExtensionTest.php index cd6084c5e3..c09ed8bc8c 100644 --- a/src/Symfony/Bundle/DebugBundle/Tests/DependencyInjection/DebugExtensionTest.php +++ b/src/Symfony/Bundle/DebugBundle/Tests/DependencyInjection/DebugExtensionTest.php @@ -15,6 +15,7 @@ use PHPUnit\Framework\TestCase; use Symfony\Bundle\DebugBundle\DependencyInjection\DebugExtension; use Symfony\Component\DependencyInjection\ContainerBuilder; use Symfony\Component\DependencyInjection\ParameterBag\ParameterBag; +use Symfony\Component\VarDumper\Caster\ReflectionCaster; class DebugExtensionTest extends TestCase { @@ -36,6 +37,39 @@ class DebugExtensionTest extends TestCase $this->assertSame($expectedTags, $container->getDefinition('data_collector.dump')->getTag('data_collector')); } + public function testUnsetClosureFileInfoShouldBeRegisteredInVarCloner() + { + if (!method_exists(ReflectionCaster::class, 'unsetClosureFileInfo')) { + $this->markTestSkipped('Method not available'); + } + + $container = $this->createContainer(); + $container->registerExtension(new DebugExtension()); + $container->loadFromExtension('debug', []); + $this->compileContainer($container); + + $definition = $container->getDefinition('var_dumper.cloner'); + + $called = false; + foreach ($definition->getMethodCalls() as $call) { + if ('addCasters' !== $call[0]) { + continue; + } + + $argument = $call[1][0] ?? null; + if (null === $argument) { + continue; + } + + if (['Closure' => ReflectionCaster::class.'::unsetClosureFileInfo'] === $argument) { + $called = true; + break; + } + } + + $this->assertTrue($called); + } + private function createContainer() { $container = new ContainerBuilder(new ParameterBag([