From cdd5c5b0ff2175863f2a369d35d1a315df1ad6c4 Mon Sep 17 00:00:00 2001 From: "Alexander M. Turek" Date: Mon, 18 Jul 2022 10:17:26 +0200 Subject: [PATCH] [VarDumper] Add a test case for nesting intersection and union types --- .../Tests/Caster/ReflectionCasterTest.php | 41 ++++++++++++++++++- ...ectionUnionTypeWithIntersectionFixture.php | 8 ++++ 2 files changed, 48 insertions(+), 1 deletion(-) create mode 100644 src/Symfony/Component/VarDumper/Tests/Fixtures/ReflectionUnionTypeWithIntersectionFixture.php diff --git a/src/Symfony/Component/VarDumper/Tests/Caster/ReflectionCasterTest.php b/src/Symfony/Component/VarDumper/Tests/Caster/ReflectionCasterTest.php index 22e4d998287bb..1940d17da0b14 100644 --- a/src/Symfony/Component/VarDumper/Tests/Caster/ReflectionCasterTest.php +++ b/src/Symfony/Component/VarDumper/Tests/Caster/ReflectionCasterTest.php @@ -20,6 +20,7 @@ use Symfony\Component\VarDumper\Tests\Fixtures\ReflectionIntersectionTypeFixture; use Symfony\Component\VarDumper\Tests\Fixtures\ReflectionNamedTypeFixture; use Symfony\Component\VarDumper\Tests\Fixtures\ReflectionUnionTypeFixture; +use Symfony\Component\VarDumper\Tests\Fixtures\ReflectionUnionTypeWithIntersectionFixture; /** * @author Nicolas Grekas @@ -78,7 +79,7 @@ public function testClosureCaster() $b: & 123 } file: "%sReflectionCasterTest.php" - line: "71 to 71" + line: "72 to 72" } EOTXT , $var @@ -326,6 +327,44 @@ public function testReflectionIntersectionType() ); } + /** + * @requires PHP 8.2 + */ + public function testReflectionUnionTypeWithIntersection() + { + $var = (new \ReflectionProperty(ReflectionUnionTypeWithIntersectionFixture::class, 'a'))->getType(); + $this->assertDumpMatchesFormat( + <<<'EOTXT' +ReflectionUnionType { + allowsNull: true + types: array:2 [ + 0 => ReflectionIntersectionType { + allowsNull: false + types: array:2 [ + 0 => ReflectionNamedType { + name: "Traversable" + allowsNull: false + isBuiltin: false + } + 1 => ReflectionNamedType { + name: "Countable" + allowsNull: false + isBuiltin: false + } + ] + } + 1 => ReflectionNamedType { + name: "null" + allowsNull: true + isBuiltin: true + } + ] +} +EOTXT + , $var + ); + } + /** * @requires PHP 8 */ diff --git a/src/Symfony/Component/VarDumper/Tests/Fixtures/ReflectionUnionTypeWithIntersectionFixture.php b/src/Symfony/Component/VarDumper/Tests/Fixtures/ReflectionUnionTypeWithIntersectionFixture.php new file mode 100644 index 0000000000000..630d0e77f69e6 --- /dev/null +++ b/src/Symfony/Component/VarDumper/Tests/Fixtures/ReflectionUnionTypeWithIntersectionFixture.php @@ -0,0 +1,8 @@ +