From 65cf773322c707e61a9cf882aa9cdb94519f441a Mon Sep 17 00:00:00 2001 From: patrykbaszak Date: Fri, 16 Aug 2024 07:25:59 +0200 Subject: [PATCH] all type resolved cases tested --- .../Factories/TypeReflectionFactoryTest.php | 44 +++++++++++++++++-- 1 file changed, 41 insertions(+), 3 deletions(-) diff --git a/tests/Unit/Reflection/Domain/Factories/TypeReflectionFactoryTest.php b/tests/Unit/Reflection/Domain/Factories/TypeReflectionFactoryTest.php index 9fc2efb..1009c07 100644 --- a/tests/Unit/Reflection/Domain/Factories/TypeReflectionFactoryTest.php +++ b/tests/Unit/Reflection/Domain/Factories/TypeReflectionFactoryTest.php @@ -24,17 +24,55 @@ class TypeReflectionFactoryTest extends TestCase { #[Test] - public function shouldReturnMixedType(): void + public function shouldReturnStringTypeForProperty(): void { $factory = new TypeReflectionFactory(); $obj = new class() { - public $property; + public string $property; }; /** @var NamedTypeReflection $reflection */ $reflection = $factory->createForProperty(new \ReflectionProperty(get_class($obj), 'property')); - $this->assertEquals('mixed', $reflection->name()); + $this->assertEquals('string', $reflection->name()); + $this->assertEquals(NamedTypeReflection::IS_BUILT_IN, $reflection->flags()); + $this->assertTrue($reflection->isBuiltIn()); + } + + #[Test] + public function shouldReturnStringTypeForMethod(): void + { + $factory = new TypeReflectionFactory(); + $obj = new class() { + public function test(): string + { + return 'test'; + } + }; + + /** @var NamedTypeReflection $reflection */ + $reflection = $factory->createForMethod(new \ReflectionMethod(get_class($obj), 'test')); + + $this->assertEquals('string', $reflection->name()); + $this->assertEquals(NamedTypeReflection::IS_BUILT_IN, $reflection->flags()); + $this->assertTrue($reflection->isBuiltIn()); + } + + #[Test] + public function shouldReturnStringTypeForPameter(): void + { + $factory = new TypeReflectionFactory(); + $obj = new class() { + public function test(string $parameter): string + { + return 'test'; + } + }; + + /** @var NamedTypeReflection $reflection */ + $reflection = $factory->createForParameter((new \ReflectionMethod(get_class($obj), 'test'))->getParameters()[0]); + + $this->assertEquals('string', $reflection->name()); $this->assertEquals(NamedTypeReflection::IS_BUILT_IN, $reflection->flags()); $this->assertTrue($reflection->isBuiltIn()); }