Skip to content

Commit

Permalink
bug #53842 [VarDumper] Fix configuring CliDumper with SYMFONY_IDE env…
Browse files Browse the repository at this point in the history
… var (nicolas-grekas)

This PR was merged into the 6.4 branch.

Discussion
----------

[VarDumper] Fix configuring CliDumper with SYMFONY_IDE env var

| Q             | A
| ------------- | ---
| Branch?       | 6.4
| Bug fix?      | yes
| New feature?  | no
| Deprecations? | no
| Issues        | -
| License       | MIT

When using `dump()` in a plain PHP script, `SYMFONY_IDE` is currently ignored. This fixes it when `FileLinkFormatter` is available.

Commits
-------

266ab4e299 [VarDumper] Fix configuring CliDumper with SYMFONY_IDE env var
  • Loading branch information
nicolas-grekas committed Feb 8, 2024
2 parents 81ae1a4 + 5cde1af commit b1040d4
Show file tree
Hide file tree
Showing 2 changed files with 30 additions and 2 deletions.
3 changes: 2 additions & 1 deletion Dumper/CliDumper.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand Down Expand Up @@ -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');
}

/**
Expand Down
29 changes: 28 additions & 1 deletion Tests/Dumper/CliDumperTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -479,7 +480,7 @@ public function testCollapse()
],
[
'bar' => 123,
]
],
]);

$dumper = new CliDumper();
Expand All @@ -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;
}
}
}
}

0 comments on commit b1040d4

Please sign in to comment.