bug #32129 [DebugBundle] fix register ReflectionCaster::unsetClosureFileInfo caster in var cloner service (alekitto)
This PR was merged into the 4.3 branch.
Discussion
----------
[DebugBundle] fix register ReflectionCaster::unsetClosureFileInfo caster in var cloner service
| Q | A
| ------------- | ---
| Branch? | 4.3
| Bug fix? | yes
| New feature? | no
| BC breaks? | no
| Deprecations? | no
| Tests pass? | yes
| License | MIT
Non-existent class was checked by `method_exists` in Debug bundle.
This should fix (and correctly register) the caster while loading `DebugExtension` from `DebugBundle`
Commits
-------
860164ee7e
[DebugBundle] fix register ReflectionCaster::unsetClosureFileInfo caster in var cloner service
This commit is contained in:
commit
6d02c89c21
@ -17,6 +17,7 @@ use Symfony\Component\DependencyInjection\ContainerBuilder;
|
|||||||
use Symfony\Component\DependencyInjection\Extension\Extension;
|
use Symfony\Component\DependencyInjection\Extension\Extension;
|
||||||
use Symfony\Component\DependencyInjection\Loader\XmlFileLoader;
|
use Symfony\Component\DependencyInjection\Loader\XmlFileLoader;
|
||||||
use Symfony\Component\DependencyInjection\Reference;
|
use Symfony\Component\DependencyInjection\Reference;
|
||||||
|
use Symfony\Component\VarDumper\Caster\ReflectionCaster;
|
||||||
use Symfony\Component\VarDumper\Dumper\CliDumper;
|
use Symfony\Component\VarDumper\Dumper\CliDumper;
|
||||||
use Symfony\Component\VarDumper\Dumper\HtmlDumper;
|
use Symfony\Component\VarDumper\Dumper\HtmlDumper;
|
||||||
|
|
||||||
@ -43,9 +44,9 @@ class DebugExtension extends Extension
|
|||||||
->addMethodCall('setMinDepth', [$config['min_depth']])
|
->addMethodCall('setMinDepth', [$config['min_depth']])
|
||||||
->addMethodCall('setMaxString', [$config['max_string_length']]);
|
->addMethodCall('setMaxString', [$config['max_string_length']]);
|
||||||
|
|
||||||
if (method_exists(ReflectionClass::class, 'unsetClosureFileInfo')) {
|
if (method_exists(ReflectionCaster::class, 'unsetClosureFileInfo')) {
|
||||||
$container->getDefinition('var_dumper.cloner')
|
$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']) {
|
if (method_exists(HtmlDumper::class, 'setTheme') && 'dark' !== $config['theme']) {
|
||||||
|
@ -15,6 +15,7 @@ use PHPUnit\Framework\TestCase;
|
|||||||
use Symfony\Bundle\DebugBundle\DependencyInjection\DebugExtension;
|
use Symfony\Bundle\DebugBundle\DependencyInjection\DebugExtension;
|
||||||
use Symfony\Component\DependencyInjection\ContainerBuilder;
|
use Symfony\Component\DependencyInjection\ContainerBuilder;
|
||||||
use Symfony\Component\DependencyInjection\ParameterBag\ParameterBag;
|
use Symfony\Component\DependencyInjection\ParameterBag\ParameterBag;
|
||||||
|
use Symfony\Component\VarDumper\Caster\ReflectionCaster;
|
||||||
|
|
||||||
class DebugExtensionTest extends TestCase
|
class DebugExtensionTest extends TestCase
|
||||||
{
|
{
|
||||||
@ -36,6 +37,39 @@ class DebugExtensionTest extends TestCase
|
|||||||
$this->assertSame($expectedTags, $container->getDefinition('data_collector.dump')->getTag('data_collector'));
|
$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()
|
private function createContainer()
|
||||||
{
|
{
|
||||||
$container = new ContainerBuilder(new ParameterBag([
|
$container = new ContainerBuilder(new ParameterBag([
|
||||||
|
Reference in New Issue
Block a user