-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathConstantReaderTest.php
More file actions
97 lines (82 loc) 路 3.13 KB
/
Copy pathConstantReaderTest.php
File metadata and controls
97 lines (82 loc) 路 3.13 KB
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
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
<?php
declare(strict_types=1);
namespace TypeLang\Reader\Tests;
use PHPUnit\Framework\Attributes\DataProvider;
use PHPUnit\Framework\Attributes\Group;
use PHPUnit\Framework\Attributes\RequiresPhp;
use TypeLang\Reader\ConstantReaderInterface;
use TypeLang\Reader\Tests\Stub\__ConstantReaderEnum;
use TypeLang\Reader\Tests\Stub\ConstantReaderStub;
use TypeLang\Reader\Tests\Stub\ConstantReaderStub83;
use TypeLang\Type\IntersectionTypeNode;
use TypeLang\Type\NullableTypeNode;
use TypeLang\Type\UnionTypeNode;
#[Group('type-lang/reader')]
class ConstantReaderTest extends ReaderTestCase
{
#[DataProvider('readersDataProvider')]
#[RequiresPhp('>= 8.3.0')]
public function testSimpleType(ConstantReaderInterface $reader): void
{
$type = $reader->findConstantType(
constant: new \ReflectionClassConstant(ConstantReaderStub83::class, 'SINGLE'),
);
self::assertSameType(self::builtin('int'), $type);
}
#[DataProvider('readersDataProvider')]
#[RequiresPhp('>= 8.3.0')]
public function testUnionType(ConstantReaderInterface $reader): void
{
$type = $reader->findConstantType(
constant: new \ReflectionClassConstant(ConstantReaderStub83::class, 'UNION'),
);
self::assertSameType(new UnionTypeNode([
self::builtin('string'),
self::builtin('int')
]), $type);
}
#[DataProvider('readersDataProvider')]
#[RequiresPhp('>= 8.3.0')]
public function testIntersectionType(ConstantReaderInterface $reader): void
{
$type = $reader->findConstantType(
constant: new \ReflectionClassConstant(ConstantReaderStub83::class, 'INTERSECTION'),
);
self::assertSameType(new IntersectionTypeNode([
self::classType(__ConstantReaderEnum::class),
self::classType(\BackedEnum::class)
]), $type);
}
#[DataProvider('readersDataProvider')]
#[RequiresPhp('>= 8.3.0')]
public function testCompositeType(ConstantReaderInterface $reader): void
{
$type = $reader->findConstantType(
constant: new \ReflectionClassConstant(ConstantReaderStub83::class, 'COMPOSITE'),
);
self::assertSameType(new UnionTypeNode([
new IntersectionTypeNode([
self::classType(__ConstantReaderEnum::class),
self::classType(\BackedEnum::class)
]),
self::builtin('array')
]), $type);
}
#[DataProvider('readersDataProvider')]
#[RequiresPhp('>= 8.3.0')]
public function testNullableType(ConstantReaderInterface $reader): void
{
$type = $reader->findConstantType(
constant: new \ReflectionClassConstant(ConstantReaderStub83::class, 'NULLABLE'),
);
self::assertSameType(new NullableTypeNode(self::builtin('int')), $type);
}
#[DataProvider('readersDataProvider')]
public function testUntypedConstantHasNoType(ConstantReaderInterface $reader): void
{
$type = $reader->findConstantType(
constant: new \ReflectionClassConstant(ConstantReaderStub::class, 'UNTYPED'),
);
self::assertNull($type);
}
}