From 94071c34c9ee2be4ed57e06cae857b838de35295 Mon Sep 17 00:00:00 2001 From: Travis Sheldon Date: Fri, 18 Oct 2024 07:13:48 -0400 Subject: [PATCH] fix: type reflector uses wrong definition when converting to class (#592) Co-authored-by: Brent Roose --- src/Tempest/Reflection/src/TypeReflector.php | 2 +- src/Tempest/Reflection/tests/ReflectionTypeTest.php | 13 +++++++++++++ 2 files changed, 14 insertions(+), 1 deletion(-) diff --git a/src/Tempest/Reflection/src/TypeReflector.php b/src/Tempest/Reflection/src/TypeReflector.php index 6c971036a..80708d84e 100644 --- a/src/Tempest/Reflection/src/TypeReflector.php +++ b/src/Tempest/Reflection/src/TypeReflector.php @@ -51,7 +51,7 @@ public function __construct( public function asClass(): ClassReflector { - return new ClassReflector($this->definition); + return new ClassReflector($this->cleanDefinition); } public function equals(string|TypeReflector $type): bool diff --git a/src/Tempest/Reflection/tests/ReflectionTypeTest.php b/src/Tempest/Reflection/tests/ReflectionTypeTest.php index 83c60da21..b3c63dc17 100644 --- a/src/Tempest/Reflection/tests/ReflectionTypeTest.php +++ b/src/Tempest/Reflection/tests/ReflectionTypeTest.php @@ -39,4 +39,17 @@ public static function data(): Generator yield ['string', null, false]; yield ['?string', null, true]; } + + public function test_as_class(): void + { + $this->assertSame( + expected: A::class, + actual: (new TypeReflector('Tempest\Reflection\Tests\Fixtures\A'))->asClass()->getName(), + ); + + $this->assertSame( + expected: A::class, + actual: (new TypeReflector('?Tempest\Reflection\Tests\Fixtures\A'))->asClass()->getName(), + ); + } }