Skip to content

Commit af2407f

Browse files
Merge branch '3.4' into 4.4
* 3.4: [3.4] Fix support for PHP8 union types [PhpUnitBridge] Streamline ansi/no-ansi of composer according to phpunit --colors option [3.4] Small update in our internal terminology [Cache] fix compat with DBAL v3 [VarDumper] Fix CliDumper coloration [DI] tighten detection of local dirs to prevent false positives [FrameworkBundle] preserve dots in query-string when redirecting bumped Symfony version to 3.4.43 updated VERSION for 3.4.42 update CONTRIBUTORS for 3.4.42 updated CHANGELOG for 3.4.42
2 parents 56b3aa5 + 3052823 commit af2407f

File tree

3 files changed

+64
-7
lines changed

3 files changed

+64
-7
lines changed

Caster/ReflectionCaster.php

Lines changed: 10 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -97,7 +97,7 @@ public static function castType(\ReflectionType $c, array $a, Stub $stub, $isNes
9797
$prefix = Caster::PREFIX_VIRTUAL;
9898

9999
$a += [
100-
$prefix.'name' => $c->getName(),
100+
$prefix.'name' => $c instanceof \ReflectionNamedType ? $c->getName() : (string) $c,
101101
$prefix.'allowsNull' => $c->allowsNull(),
102102
$prefix.'isBuiltin' => $c->isBuiltin(),
103103
];
@@ -182,7 +182,7 @@ public static function castFunctionAbstract(\ReflectionFunctionAbstract $c, arra
182182

183183
if (isset($a[$prefix.'returnType'])) {
184184
$v = $a[$prefix.'returnType'];
185-
$v = $v->getName();
185+
$v = $v instanceof \ReflectionNamedType ? $v->getName() : (string) $v;
186186
$a[$prefix.'returnType'] = new ClassStub($a[$prefix.'returnType']->allowsNull() ? '?'.$v : $v, [class_exists($v, false) || interface_exists($v, false) || trait_exists($v, false) ? $v : '', '']);
187187
}
188188
if (isset($a[$prefix.'class'])) {
@@ -244,7 +244,7 @@ public static function castParameter(\ReflectionParameter $c, array $a, Stub $st
244244
]);
245245

246246
if ($v = $c->getType()) {
247-
$a[$prefix.'typeHint'] = $v->getName();
247+
$a[$prefix.'typeHint'] = $v instanceof \ReflectionNamedType ? $v->getName() : (string) $v;
248248
}
249249

250250
if (isset($a[$prefix.'typeHint'])) {
@@ -320,10 +320,14 @@ public static function getSignature(array $a)
320320
foreach ($a[$prefix.'parameters']->value as $k => $param) {
321321
$signature .= ', ';
322322
if ($type = $param->getType()) {
323-
if (!$param->isOptional() && $param->allowsNull()) {
324-
$signature .= '?';
323+
if (!$type instanceof \ReflectionNamedType) {
324+
$signature .= $type.' ';
325+
} else {
326+
if (!$param->isOptional() && $param->allowsNull()) {
327+
$signature .= '?';
328+
}
329+
$signature .= substr(strrchr('\\'.$type->getName(), '\\'), 1);
325330
}
326-
$signature .= substr(strrchr('\\'.$type->getName(), '\\'), 1).' ';
327331
}
328332
$signature .= $k;
329333

Dumper/CliDumper.php

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -287,7 +287,8 @@ public function enterHash(Cursor $cursor, $type, $class, $hasChild)
287287
} elseif (Cursor::HASH_RESOURCE === $type) {
288288
$prefix = $this->style('note', $class.' resource', $attr).($hasChild ? ' {' : ' ');
289289
} else {
290-
$prefix = $class && !(self::DUMP_LIGHT_ARRAY & $this->flags) ? $this->style('note', 'array:'.$class, $attr).' [' : '[';
290+
$unstyledPrefix = $class && !(self::DUMP_LIGHT_ARRAY & $this->flags) ? 'array:'.$class : '';
291+
$prefix = $this->style('note', $unstyledPrefix, $attr).($unstyledPrefix ? ' [' : '[');
291292
}
292293

293294
if (($cursor->softRefCount || 0 < $cursor->softRefHandle) && empty($attr['cut_hash'])) {

Tests/Dumper/CliDumperTest.php

Lines changed: 52 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@
1313

1414
use PHPUnit\Framework\TestCase;
1515
use Symfony\Component\VarDumper\Cloner\VarCloner;
16+
use Symfony\Component\VarDumper\Dumper\AbstractDumper;
1617
use Symfony\Component\VarDumper\Dumper\CliDumper;
1718
use Symfony\Component\VarDumper\Test\VarDumperTestTrait;
1819
use Twig\Environment;
@@ -517,6 +518,57 @@ public function testIncompleteClass()
517518
);
518519
}
519520

521+
public function provideDumpArrayWithColor()
522+
{
523+
yield [
524+
['foo' => 'bar'],
525+
0,
526+
<<<EOTXT
527+
\e[0;38;5;208m\e[38;5;38marray:1\e[0;38;5;208m [\e[m
528+
\e[0;38;5;208m"\e[38;5;113mfoo\e[0;38;5;208m" => "\e[1;38;5;113mbar\e[0;38;5;208m"\e[m
529+
\e[0;38;5;208m]\e[m
530+
531+
EOTXT
532+
];
533+
534+
yield [[], AbstractDumper::DUMP_LIGHT_ARRAY, "\e[0;38;5;208m\e[38;5;38m\e[0;38;5;208m[]\e[m\n"];
535+
536+
yield [
537+
['foo' => 'bar'],
538+
AbstractDumper::DUMP_LIGHT_ARRAY,
539+
<<<EOTXT
540+
\e[0;38;5;208m\e[38;5;38m\e[0;38;5;208m[\e[m
541+
\e[0;38;5;208m"\e[38;5;113mfoo\e[0;38;5;208m" => "\e[1;38;5;113mbar\e[0;38;5;208m"\e[m
542+
\e[0;38;5;208m]\e[m
543+
544+
EOTXT
545+
];
546+
547+
yield [[], 0, "\e[0;38;5;208m\e[38;5;38m\e[0;38;5;208m[]\e[m\n"];
548+
}
549+
550+
/**
551+
* @dataProvider provideDumpArrayWithColor
552+
*/
553+
public function testDumpArrayWithColor($value, $flags, $expectedOut)
554+
{
555+
if ('\\' === \DIRECTORY_SEPARATOR) {
556+
$this->markTestSkipped('Windows console does not support coloration');
557+
}
558+
559+
$out = '';
560+
$dumper = new CliDumper(function ($line, $depth) use (&$out) {
561+
if ($depth >= 0) {
562+
$out .= str_repeat(' ', $depth).$line."\n";
563+
}
564+
}, null, $flags);
565+
$dumper->setColors(true);
566+
$cloner = new VarCloner();
567+
$dumper->dump($cloner->cloneVar($value));
568+
569+
$this->assertSame($expectedOut, $out);
570+
}
571+
520572
private function getSpecialVars()
521573
{
522574
foreach (array_keys($GLOBALS) as $var) {

0 commit comments

Comments
 (0)