-
-
Notifications
You must be signed in to change notification settings - Fork 146
/
Reflection.getPropertyType.phpt
48 lines (37 loc) 路 1.17 KB
/
Reflection.getPropertyType.phpt
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
<?php
/**
* Test: Nette\Utils\Reflection::getPropertyType
*/
declare(strict_types=1);
use Nette\Utils\Reflection;
use Test\B; // for testing purposes
use Tester\Assert;
require __DIR__ . '/../bootstrap.php';
class A
{
public Undeclared $undeclared;
public B $b;
public array $array;
public self $self;
public $none;
public ?B $nullable;
public mixed $mixed;
public array|self $union;
public array|self|null $nullableUnion;
}
class AExt extends A
{
public parent $parent;
}
$class = new ReflectionClass('A');
$props = $class->getProperties();
Assert::same('Undeclared', (string) Reflection::getPropertyType($props[0]));
Assert::same('Test\B', (string) Reflection::getPropertyType($props[1]));
Assert::same('array', (string) Reflection::getPropertyType($props[2]));
Assert::same('A', (string) Reflection::getPropertyType($props[3]));
Assert::null(Reflection::getPropertyType($props[4]));
Assert::same('?Test\B', (string) Reflection::getPropertyType($props[5]));
Assert::same('mixed', (string) Reflection::getPropertyType($props[6]));
$class = new ReflectionClass('AExt');
$props = $class->getProperties();
Assert::same('A', (string) Reflection::getPropertyType($props[0]));