Skip to content

Commit 233e3f0

Browse files
committed
[DebugBundle] fix register ReflectionCaster::unsetClosureFileInfo caster in var cloner service
1 parent 9b80d1c commit 233e3f0

File tree

2 files changed

+37
-2
lines changed

2 files changed

+37
-2
lines changed

DependencyInjection/DebugExtension.php

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@
1717
use Symfony\Component\DependencyInjection\Extension\Extension;
1818
use Symfony\Component\DependencyInjection\Loader\XmlFileLoader;
1919
use Symfony\Component\DependencyInjection\Reference;
20+
use Symfony\Component\VarDumper\Caster\ReflectionCaster;
2021
use Symfony\Component\VarDumper\Dumper\CliDumper;
2122
use Symfony\Component\VarDumper\Dumper\HtmlDumper;
2223

@@ -43,9 +44,9 @@ public function load(array $configs, ContainerBuilder $container)
4344
->addMethodCall('setMinDepth', [$config['min_depth']])
4445
->addMethodCall('setMaxString', [$config['max_string_length']]);
4546

46-
if (method_exists(ReflectionClass::class, 'unsetClosureFileInfo')) {
47+
if (method_exists(ReflectionCaster::class, 'unsetClosureFileInfo')) {
4748
$container->getDefinition('var_dumper.cloner')
48-
->addMethodCall('addCasters', ReflectionClass::UNSET_CLOSURE_FILE_INFO);
49+
->addMethodCall('addCasters', [ReflectionCaster::UNSET_CLOSURE_FILE_INFO]);
4950
}
5051

5152
if (method_exists(HtmlDumper::class, 'setTheme') && 'dark' !== $config['theme']) {

Tests/DependencyInjection/DebugExtensionTest.php

Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@
1515
use Symfony\Bundle\DebugBundle\DependencyInjection\DebugExtension;
1616
use Symfony\Component\DependencyInjection\ContainerBuilder;
1717
use Symfony\Component\DependencyInjection\ParameterBag\ParameterBag;
18+
use Symfony\Component\VarDumper\Caster\ReflectionCaster;
1819

1920
class DebugExtensionTest extends TestCase
2021
{
@@ -36,6 +37,39 @@ public function testLoadWithoutConfiguration()
3637
$this->assertSame($expectedTags, $container->getDefinition('data_collector.dump')->getTag('data_collector'));
3738
}
3839

40+
public function testUnsetClosureFileInfoShouldBeRegisteredInVarCloner()
41+
{
42+
if (!method_exists(ReflectionCaster::class, 'unsetClosureFileInfo')) {
43+
$this->markTestSkipped('Method not available');
44+
}
45+
46+
$container = $this->createContainer();
47+
$container->registerExtension(new DebugExtension());
48+
$container->loadFromExtension('debug', []);
49+
$this->compileContainer($container);
50+
51+
$definition = $container->getDefinition('var_dumper.cloner');
52+
53+
$called = false;
54+
foreach ($definition->getMethodCalls() as $call) {
55+
if ('addCasters' !== $call[0]) {
56+
continue;
57+
}
58+
59+
$argument = $call[1][0] ?? null;
60+
if (null === $argument) {
61+
continue;
62+
}
63+
64+
if (['Closure' => ReflectionCaster::class.'::unsetClosureFileInfo'] === $argument) {
65+
$called = true;
66+
break;
67+
}
68+
}
69+
70+
$this->assertTrue($called);
71+
}
72+
3973
private function createContainer()
4074
{
4175
$container = new ContainerBuilder(new ParameterBag([

0 commit comments

Comments
 (0)