8000 [VarDumper] Fix configuring CliDumper with SYMFONY_IDE env var by nicolas-grekas · Pull Request #53842 · symfony/symfony · GitHub
[go: up one dir, main page]

Skip to content

[VarDumper] Fix configuring CliDumper with SYMFONY_IDE env var #53842

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Feb 8, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ class FileLinkFormatter
private \Closure|string|null $urlFormat;

/**
* @param string|\Closure $urlFormat the URL format, or a closure that returns it on-demand
* @param string|\Closure $urlFormat The URL format, or a closure that returns it on-demand
*/
public function __construct(string|array|null $fileLinkFormat = null, ?RequestStack $requestStack = null, ?string $baseDir = null, string|\Closure|null $urlFormat = null)
{
Expand Down
3 changes: 2 additions & 1 deletion src/Symfony/Component/VarDumper/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 src/Symfony/Component/VarDumper/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