Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit 2572ddd

Browse files
committed
Fixing tests for class src/Symfony/Component/VarDumper/Tests/Dumper/CliDumperTest.php
1 parent c7cc20a commit 2572ddd

File tree

6 files changed

+88
-87
lines changed

6 files changed

+88
-87
lines changed

src/Symfony/Component/VarDumper/Dumper/CliDumper.php

Lines changed: 55 additions & 59 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,8 @@
2424
*/
2525
class CliDumper extends AbstractDumper
2626
{
27+
const DUMP_DUMP_LOCATION = 16;
28+
2729
public static $defaultColors;
2830
public static $defaultOutput = 'php://stdout';
2931

@@ -88,6 +90,12 @@ public function __construct($output = null, string $charset = null, int $flags =
8890
]);
8991
}
9092

93+
$backtrace = debug_backtrace();
94+
$caller = array_shift($backtrace);
95+
$this->attr['file'] = $caller['file'];
96+
$this->attr['line'] = $caller['line'];
97+
$this->handlesHrefGracefully = 'JetBrains-JediTerm' !== getenv('TERMINAL_EMULATOR');
98+
9199
$this->displayOptions['fileLinkFormat'] = ini_get('xdebug.file_link_format') ?: get_cfg_var('xdebug.file_link_format') ?: 'file://%f';
92100
}
93101

@@ -131,23 +139,12 @@ public function setDisplayOptions(array $displayOptions)
131139
$this->displayOptions = $displayOptions + $this->displayOptions;
132140
}
133141

134-
/**
135-
* {@inheritdoc}
136-
*/
137-
public function dump(Data $data, $output = null, array $extraDisplayOptions = [])
138-
{
139-
$this->extraDisplayOptions = $extraDisplayOptions;
140-
$result = parent::dump($data, $output);
141-
142-
return $result;
143-
}
144-
145142
/**
146143
* Configures file of the dump call function.
147144
*
148145
* @param string $file File path issued from debug_backtrace
149146
*/
150-
public function setFile(string $file)
147+
public function setFile(?string $file)
151148
{
152149
$this->attr['file'] = $file;
153150
}
@@ -157,7 +154,7 @@ public function setFile(string $file)
157154
*
158155
* @param int $line File line issued from debug_backtrace
159156
*/
160-
public function setLine(int $line)
157+
public function setLine(?int $line)
161158
{
162159
$this->attr['line'] = $line;
163160
}
@@ -334,7 +331,7 @@ public function enterHash(Cursor $cursor, $type, $class, $hasChild)
334331
$prefix = substr($prefix, 0, -1);
335332
}
336333

337-
$this->line .= $prefix;
334+
$this->line .= $prefix . $this->dumpLocation($cursor, $attr);
338335

339336
if ($hasChild) {
340337
$this->dumpLine($cursor->depth);
@@ -470,10 +467,6 @@ protected function style($style, $value, $attr = [])
470467
$this->colors = $this->supportsColors();
471468
}
472469

473-
if (null === $this->handlesHrefGracefully) {
474-
$this->handlesHrefGracefully = 'JetBrains-JediTerm' !== getenv('TERMINAL_EMULATOR');
475-
}
476-
477470
if (isset($attr['ellipsis'], $attr['ellipsis-type'])) {
478471
$prefix = substr($value, 0, -$attr['ellipsis']);
479472
if ('cli' === \PHP_SAPI && 'path' === $attr['ellipsis-type'] && isset($_SERVER[$pwd = '\\' === \DIRECTORY_SEPARATOR ? 'CD' : 'PWD']) && 0 === strpos($prefix, $_SERVER[$pwd])) {
@@ -487,47 +480,31 @@ protected function style($style, $value, $attr = [])
487480
}
488481

489482
$value = $this->style('default', $prefix).$this->style($style, $value);
490-
491-
goto href;
492-
}
493-
494-
$map = static::$controlCharsMap;
495-
$startCchr = $this->colors ? "\033[m\033[{$this->styles['default']}m" : '';
496-
$endCchr = $this->colors ? "\033[m\033[{$this->styles[$style]}m" : '';
497-
$value = preg_replace_callback(static::$controlCharsRx, function ($c) use ($map, $startCchr, $endCchr) {
498-
$s = $startCchr;
499-
$c = $c[$i = 0];
500-
do {
501-
$s .= isset($map[$c[$i]]) ? $map[$c[$i]] : sprintf('\x%02X', \ord($c[$i]));
502-
} while (isset($c[++$i]));
503-
504-
return $s.$endCchr;
505-
}, $value, -1, $cchrCount);
506-
507-
if ($this->colors) {
508-
if ($cchrCount && "\033" === $value[0]) {
509-
$value = substr($value, \strlen($startCchr));
510-
} else {
511-
$value = "\033[{$this->styles[$style]}m".$value;
512-
}
513-
if ($cchrCount && $endCchr === substr($value, -\strlen($endCchr))) {
514-
$value = substr($value, 0, -\strlen($endCchr));
515-
} else {
516-
$value .= "\033[{$this->styles['default']}m";
517-
}
518-
}
519-
520-
href:
521-
if ($this->colors && $this->handlesHrefGracefully) {
522-
if (isset($attr['file']) && $href = $this->getSourceLink($attr['file'], isset($attr['line']) ? $attr['line'] : 0)) {
523-
if ('note' === $style) {
524-
$value .= "\033]8;;{$href}\033\\^\033]8;;\033\\";
483+
} else {
484+
$map = static::$controlCharsMap;
485+
$startCchr = $this->colors ? "\033[m\033[{$this->styles['default']}m" : '';
486+
$endCchr = $this->colors ? "\033[m\033[{$this->styles[$style]}m" : '';
487+
$value = preg_replace_callback(static::$controlCharsRx, function ($c) use ($map, $startCchr, $endCchr) {
488+
$s = $startCchr;
489+
$c = $c[$i = 0];
490+
do {
491+
$s .= isset($map[$c[$i]]) ? $map[$c[$i]] : sprintf('\x%02X', \ord($c[$i]));
492+
} while (isset($c[++$i]));
493+
494+
return $s.$endCchr;
495+
}, $value, -1, $cchrCount);
496+
497+
if ($this->colors) {
498+
if ($cchrCount && "\033" === $value[0]) {
499+
$value = substr($value, \strlen($startCchr));
525500
} else {
526-
$attr['href'] = $href;
501+
$value = "\033[{$this->styles[$style]}m".$value;
502+
}
503+
if ($cchrCount && $endCchr === substr($value, -\strlen($endCchr))) {
504+
$value = substr($value, 0, -\strlen($endCchr));
505+
} else {
506+
$value .= "\033[{$this->styles['default']}m";
527507
}
528-
}
529-
if (isset($attr['href'])) {
530-
$value .= " \033]8;;{$attr['href']}\033\\[^]\033]8;;\033\\";
531508
}
532509
}
533510

@@ -668,10 +645,29 @@ private function isWindowsTrueColor()
668645
return $result;
669646
}
670647

671-
private function getSourceLink($file, $line)
648+
/**
649+
* Return the substring with the dump() function file location to get displayed with a small caret after
650+
* an hash.
651+
*
652+
* @param Cursor $cursor
653+
* @param array $attr
654+
* @return string
655+
*/
656+
private function dumpLocation(Cursor $cursor, $attr = []) :string
657+
{
658+
if ($this->handlesHrefGracefully && $cursor->depth === 0 && isset($attr['file']) && $href = $this->getSourceLink($attr['file'], $attr['line'])) {
659+
$color = $this->colors ? "\033" : '';
660+
661+
return " {$color}]8;;{$href}{$color}\\[^]{$color}]8;;{$color}\\";
662+
}
663+
664+
return '';
665+
}
666+
667+
private function getSourceLink($file, $lineNumber)
672668
{
673669
if ($fmt = $this->displayOptions['fileLinkFormat']) {
674-
return \is_string($fmt) ? strtr($fmt, ['%f' => $file, '%l' => $line]) : ($fmt->format($file, $line) ?: 'file://'.$file);
670+
return \is_string($fmt) ? strtr($fmt, ['%f' => $file, '%l' => $lineNumber]) : ($fmt->format($file, $lineNumber) ?: 'file://'.$file);
675671
}
676672

677673
return false;

src/Symfony/Component/VarDumper/Resources/functions/dump.php

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -17,11 +17,10 @@
1717
*/
1818
function dump($var, ...$moreVars)
1919
{
20-
$backtrace = debug_backtrace();
21-
VarDumper::dump($var, $backtrace);
20+
VarDumper::dump($var);
2221

2322
foreach ($moreVars as $v) {
24-
VarDumper::dump($v, $backtrace);
23+
VarDumper::dump($v);
2524
}
2625

2726
if (1 < func_num_args()) {
@@ -35,9 +34,8 @@ function dump($var, ...$moreVars)
3534
if (!function_exists('dd')) {
3635
function dd(...$vars)
3736
{
38-
$backtrace = debug_backtrace();
3937
foreach ($vars as $v) {
40-
VarDumper::dump($v, $backtrace);
38+
VarDumper::dump($v);
4139
}
4240

4341
die(1);

src/Symfony/Component/VarDumper/Test/VarDumperTestTrait.php

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,8 @@ protected function getDump($data, $key = null, $filter = 0)
3939
$cloner->setMaxItems(-1);
4040
$dumper = new CliDumper(null, null, $flags);
4141
$dumper->setColors(false);
42+
$dumper->setFile(null);
43+
$dumper->setLine(null);
4244
$data = $cloner->cloneVar($data, $filter)->withRefHandles(false);
4345
if (null !== $key && null === $data = $data->seek($key)) {
4446
return;

src/Symfony/Component/VarDumper/Tests/Caster/IntlCasterTest.php

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,6 @@ public function testCastNumberFormatter()
4040

4141
$expectedLocale = $var->getLocale();
4242
$expectedPattern = $var->getPattern();
43-
dump("Here is a dummy dump.");
4443

4544
$expectedAttribute1 = $var->getAttribute(\NumberFormatter::PARSE_INT_ONLY);
4645
$expectedAttribute2 = $var->getAttribute(\NumberFormatter::GROUPING_USED);

0 commit comments

Comments
 (0)