Skip to content

Commit

Permalink
all type resolved cases tested
Browse files Browse the repository at this point in the history
  • Loading branch information
patrykbaszak committed Aug 16, 2024
1 parent 22da784 commit 65cf773
Showing 1 changed file with 41 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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());
}
Expand Down

0 comments on commit 65cf773

Please sign in to comment.