1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55
|
<?php
declare(strict_types=1);
use Nette\Utils\Type;
use Tester\Assert;
require __DIR__ . '/../bootstrap.php';
$type = Type::fromReflection((new ReflectionObject(new class {
public function foo(): string
{
}
}))->getMethod('foo'));
Assert::same(['string'], $type->getNames());
Assert::same('string', (string) $type);
$type = Type::fromReflection((new ReflectionObject(new class {
public function foo(): ?string
{
}
}))->getMethod('foo'));
Assert::same(['string', 'null'], $type->getNames());
Assert::same('?string', (string) $type);
$class = new class {
public function foo(): self
{
}
};
$type = Type::fromReflection((new ReflectionObject($class))->getMethod('foo'));
Assert::same([$class::class], $type->getNames());
Assert::same($class::class, (string) $type);
class ParentClass
{
public function foo(): static
{
}
}
class ChildClass extends ParentClass
{
}
$type = Type::fromReflection(new Nette\Utils\ReflectionMethod(ChildClass::class, 'foo'));
Assert::same([ChildClass::class], $type->getNames());
Assert::same(ChildClass::class, (string) $type);
|