From 5cde1af73baad9b6e42b0a7dcdd4434fda55bf5f Mon Sep 17 00:00:00 2001 From: Nicolas Grekas Date: Wed, 7 Feb 2024 17:01:06 +0100 Subject: [PATCH] [VarDumper] Fix configuring CliDumper with SYMFONY_IDE env var --- Dumper/CliDumper.php | 3 ++- Tests/Dumper/CliDumperTest.php | 29 ++++++++++++++++++++++++++++- 2 files changed, 30 insertions(+), 2 deletions(-) diff --git a/Dumper/CliDumper.php b/Dumper/CliDumper.php index af96370..9d9bdf8 100644 --- a/Dumper/CliDumper.php +++ b/Dumper/CliDumper.php @@ -11,6 +11,7 @@ namespace Symfony\Component\VarDumper\Dumper; +use Symfony\Component\ErrorHandler\ErrorRenderer\FileLinkFormatter; use Symfony\Component\VarDumper\Cloner\Cursor; use Symfony\Component\VarDumper\Cloner\Stub; @@ -82,7 +83,7 @@ public function __construct($output = null, ?string $charset = null, int $flags ]); } - $this->displayOptions['fileLinkFormat'] = \ini_get('xdebug.file_link_format') ?: get_cfg_var('xdebug.file_link_format') ?: 'file://%f#L%l'; + $this->displayOptions['fileLinkFormat'] = class_exists(FileLinkFormatter::class) ? new FileLinkFormatter() : (\ini_get('xdebug.file_link_format') ?: get_cfg_var('xdebug.file_link_format') ?: 'file://%f#L%l'); } /** diff --git a/Tests/Dumper/CliDumperTest.php b/Tests/Dumper/CliDumperTest.php index 37b7080..1b69df1 100644 --- a/Tests/Dumper/CliDumperTest.php +++ b/Tests/Dumper/CliDumperTest.php @@ -12,6 +12,7 @@ namespace Symfony\Component\VarDumper\Tests\Dumper; use PHPUnit\Framework\TestCase; +use Symfony\Component\VarDumper\Caster\ClassStub; use Symfony\Component\VarDumper\Caster\CutStub; use Symfony\Component\VarDumper\Cloner\Data; use Symfony\Component\VarDumper\Cloner\Stub; @@ -479,7 +480,7 @@ public function testCollapse() ], [ 'bar' => 123, - ] + ], ]); $dumper = new CliDumper(); @@ -499,4 +500,30 @@ public function testCollapse() $dump ); } + + public function testFileLinkFormat() + { + $data = new Data([ + [ + new ClassStub(self::class), + ], + ]); + + $ide = $_ENV['SYMFONY_IDE'] ?? null; + $_ENV['SYMFONY_IDE'] = 'vscode'; + + try { + $dumper = new CliDumper(); + $dumper->setColors(true); + $dump = $dumper->dump($data, true); + + $this->assertStringMatchesFormat('%svscode:%sCliDumperTest%s', $dump); + } finally { + if (null === $ide) { + unset($_ENV['SYMFONY_IDE']); + } else { + $_ENV['SYMFONY_IDE'] = $ide; + } + } + } }