Skip to content

Commit 7ec82fa

Browse files
Merge branch '4.4' into 5.2
* 4.4: [HttpFoundation] Fix return types of SessionHandler::gc() [Cache] Support decorated Dbal drivers in PdoAdapter [VarDumper] Support for intersection types
2 parents e24d8fc + bbfcb4d commit 7ec82fa

File tree

3 files changed

+59
-2
lines changed

3 files changed

+59
-2
lines changed

Caster/ReflectionCaster.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -102,7 +102,7 @@ public static function castType(\ReflectionType $c, array $a, Stub $stub, bool $
102102
$prefix.'allowsNull' => $c->allowsNull(),
103103
$prefix.'isBuiltin' => $c->isBuiltin(),
104104
];
105-
} elseif ($c instanceof \ReflectionUnionType) {
105+
} elseif ($c instanceof \ReflectionUnionType || $c instanceof \ReflectionIntersectionType) {
106106
$a[$prefix.'allowsNull'] = $c->allowsNull();
107107
self::addMap($a, $c, [
108108
'types' => 'getTypes',

Tests/Caster/ReflectionCasterTest.php

Lines changed: 50 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@
1818
use Symfony\Component\VarDumper\Tests\Fixtures\GeneratorDemo;
1919
use Symfony\Component\VarDumper\Tests\Fixtures\LotsOfAttributes;
2020
use Symfony\Component\VarDumper\Tests\Fixtures\NotLoadableClass;
21+
use Symfony\Component\VarDumper\Tests\Fixtures\ReflectionIntersectionTypeFixture;
2122
use Symfony\Component\VarDumper\Tests\Fixtures\ReflectionNamedTypeFixture;
2223
use Symfony\Component\VarDumper\Tests\Fixtures\ReflectionUnionTypeFixture;
2324

@@ -94,7 +95,7 @@ public function testClosureCaster()
9495
$b: & 123
9596
}
9697
file: "%sReflectionCasterTest.php"
97-
line: "87 to 87"
98+
line: "88 to 88"
9899
}
99100
EOTXT
100101
, $var
@@ -244,6 +245,26 @@ public function testReflectionParameterNullableUnion()
244245
);
245246
}
246247

248+
/**
249+
* @requires PHP 8.1
250+
*/
251+
public function testReflectionParameterIntersection()
252+
{
253+
$f = eval('return function (Traversable&Countable $a) {};');
254+
$var = new \ReflectionParameter($f, 0);
255+
256+
$this->assertDumpMatchesFormat(
257+
<<<'EOTXT'
258+
ReflectionParameter {
259+
+name: "a"
260+
position: 0
261+
typeHint: "Traversable&Countable"
262+
}
263+
EOTXT
264+
, $var
265+
);
266+
}
267+
247268
/**
248269
* @requires PHP 7.4
249270
*/
@@ -308,6 +329,34 @@ public function testReflectionUnionType()
308329
);
309330
}
310331

332+
/**
333+
* @requires PHP 8.1
334+
*/
335+
public function testReflectionIntersectionType()
336+
{
337+
$var = (new \ReflectionProperty(ReflectionIntersectionTypeFixture::class, 'a'))->getType();
338+
$this->assertDumpMatchesFormat(
339+
<<<'EOTXT'
340+
ReflectionIntersectionType {
341+
allowsNull: false
342+
types: array:2 [
343+
0 => ReflectionNamedType {
344+
name: "Traversable"
345+
allowsNull: false
346+
isBuiltin: false
347+
}
348+
1 => ReflectionNamedType {
349+
name: "Countable"
350+
allowsNull: false
351+
isBuiltin: false
352+
}
353+
]
354+
}
355+
EOTXT
356+
, $var
357+
);
358+
}
359+
311360
/**
312361
* @requires PHP 8
313362
*/
Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
<?php
2+
3+
namespace Symfony\Component\VarDumper\Tests\Fixtures;
4+
5+
class ReflectionIntersectionTypeFixture
6+
{
7+
public \Traversable&\Countable $a;
8+
}

0 commit comments

Comments
 (0)