Skip to content

Commit 60f7b05

Browse files
[HttpKernel] Fix test sensitivity on xdebug.file_link_format
1 parent 906caac commit 60f7b05

File tree

4 files changed

+10
-8
lines changed

4 files changed

+10
-8
lines changed

DataCollector/DumpDataCollector.php

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -49,8 +49,9 @@ class DumpDataCollector extends DataCollector implements DataDumperInterface
4949
*/
5050
public function __construct(Stopwatch $stopwatch = null, $fileLinkFormat = null, string $charset = null, RequestStack $requestStack = null, $dumper = null)
5151
{
52+
$fileLinkFormat = $fileLinkFormat ?: \ini_get('xdebug.file_link_format') ?: get_cfg_var('xdebug.file_link_format');
5253
$this->stopwatch = $stopwatch;
53-
$this->fileLinkFormat = $fileLinkFormat ?: \ini_get('xdebug.file_link_format') ?: get_cfg_var('xdebug.file_link_format');
54+
$this->fileLinkFormat = $fileLinkFormat instanceof FileLinkFormatter && false === $fileLinkFormat->format('', 0) ? false : $fileLinkFormat;
5455
$this->charset = $charset ?: \ini_get('php.output_encoding') ?: \ini_get('default_charset') ?: 'UTF-8';
5556
$this->requestStack = $requestStack;
5657
$this->dumper = $dumper;

Debug/FileLinkFormatter.php

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -30,12 +30,12 @@ class FileLinkFormatter
3030
private $urlFormat;
3131

3232
/**
33-
* @param string|\Closure $urlFormat the URL format, or a closure that returns it on-demand
33+
* @param string|array|null $fileLinkFormat
34+
* @param string|\Closure $urlFormat the URL format, or a closure that returns it on-demand
3435
*/
35-
public function __construct(string $fileLinkFormat = null, RequestStack $requestStack = null, string $baseDir = null, $urlFormat = null)
36+
public function __construct($fileLinkFormat = null, RequestStack $requestStack = null, string $baseDir = null, $urlFormat = null)
3637
{
37-
$fileLinkFormat = $fileLinkFormat ?: \ini_get('xdebug.file_link_format') ?: get_cfg_var('xdebug.file_link_format');
38-
if ($fileLinkFormat && !\is_array($fileLinkFormat)) {
38+
if (!\is_array($fileLinkFormat) && $fileLinkFormat = $fileLinkFormat ?: \ini_get('xdebug.file_link_format') ?: get_cfg_var('xdebug.file_link_format')) {
3939
$i = strpos($f = $fileLinkFormat, '&', max(strrpos($f, '%f'), strrpos($f, '%l'))) ?: \strlen($f);
4040
$fileLinkFormat = [substr($f, 0, $i)] + preg_split('/&([^>]++)>/', substr($f, $i), -1, \PREG_SPLIT_DELIM_CAPTURE);
4141
}

Tests/DataCollector/DumpDataCollectorTest.php

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@
1515
use Symfony\Component\HttpFoundation\Request;
1616
use Symfony\Component\HttpFoundation\Response;
1717
use Symfony\Component\HttpKernel\DataCollector\DumpDataCollector;
18+
use Symfony\Component\HttpKernel\Debug\FileLinkFormatter;
1819
use Symfony\Component\VarDumper\Cloner\Data;
1920
use Symfony\Component\VarDumper\Dumper\CliDumper;
2021
use Symfony\Component\VarDumper\Server\Connection;
@@ -28,7 +29,7 @@ public function testDump()
2829
{
2930
$data = new Data([[123]]);
3031

31-
$collector = new DumpDataCollector();
32+
$collector = new DumpDataCollector(null, new FileLinkFormatter([]));
3233

3334
$this->assertSame('dump', $collector->getName());
3435

Tests/Debug/FileLinkFormatterTest.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ class FileLinkFormatterTest extends TestCase
2020
{
2121
public function testWhenNoFileLinkFormatAndNoRequest()
2222
{
23-
$sut = new FileLinkFormatter();
23+
$sut = new FileLinkFormatter([]);
2424

2525
$this->assertFalse($sut->format('/kernel/root/src/my/very/best/file.php', 3));
2626
}
@@ -47,7 +47,7 @@ public function testWhenNoFileLinkFormatAndRequest()
4747
$request->server->set('SCRIPT_FILENAME', '/public/index.php');
4848
$request->server->set('REQUEST_URI', '/index.php/example');
4949

50-
$sut = new FileLinkFormatter(null, $requestStack, __DIR__, '/_profiler/open?file=%f&line=%l#line%l');
50+
$sut = new FileLinkFormatter([], $requestStack, __DIR__, '/_profiler/open?file=%f&line=%l#line%l');
5151

5252
$this->assertSame('http://www.example.org/_profiler/open?file=file.php&line=3#line3', $sut->format($file, 3));
5353
}

0 commit comments

Comments
 (0)