-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathFunctionReaderTest.php
More file actions
107 lines (88 loc) 路 3.35 KB
/
Copy pathFunctionReaderTest.php
File metadata and controls
107 lines (88 loc) 路 3.35 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
98
99
100
101
102
103
104
105
106
107
<?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\FunctionReaderInterface;
use TypeLang\Type\IntersectionTypeNode;
use TypeLang\Type\NullableTypeNode;
use TypeLang\Type\UnionTypeNode;
#[Group('type-lang/reader')]
class FunctionReaderTest extends ReaderTestCase
{
protected function setUp(): void
{
require_once __DIR__ . '/Stub/functions_reader_stub.php';
}
#[DataProvider('readersDataProvider')]
public function testSimpleType(FunctionReaderInterface $reader): void
{
$type = $reader->findFunctionType(
function: new \ReflectionFunction('TypeLang\Reader\Tests\Stub\get_single_type'),
);
self::assertSameType(self::builtin('int'), $type);
}
#[DataProvider('readersDataProvider')]
public function testUnionType(FunctionReaderInterface $reader): void
{
$type = $reader->findFunctionType(
function: new \ReflectionFunction('TypeLang\Reader\Tests\Stub\get_union_type'),
);
self::assertSameType(new UnionTypeNode([
self::builtin('string'),
self::builtin('int')
]), $type);
}
#[DataProvider('readersDataProvider')]
public function testIntersectionType(FunctionReaderInterface $reader): void
{
$type = $reader->findFunctionType(
function: new \ReflectionFunction('TypeLang\Reader\Tests\Stub\get_intersection_type'),
);
self::assertSameType(new IntersectionTypeNode([
self::classType(\ArrayAccess::class),
self::classType(\Traversable::class)
]), $type);
}
#[DataProvider('readersDataProvider')]
#[RequiresPhp('>= 8.2.0')]
public function testCompositeType(FunctionReaderInterface $reader): void
{
require_once __DIR__ . '/Stub/functions_reader_stub_82.php';
$type = $reader->findFunctionType(
function: new \ReflectionFunction('TypeLang\Reader\Tests\Stub\get_composite_type'),
);
self::assertSameType(new UnionTypeNode([
new IntersectionTypeNode([
self::classType(\ArrayAccess::class),
self::classType(\Traversable::class)
]),
self::builtin('array')
]), $type);
}
#[DataProvider('readersDataProvider')]
public function testNullableType(FunctionReaderInterface $reader): void
{
$type = $reader->findFunctionType(
function: new \ReflectionFunction('TypeLang\Reader\Tests\Stub\get_nullable_type'),
);
self::assertSameType(new NullableTypeNode(self::builtin('int')), $type);
}
#[DataProvider('readersDataProvider')]
public function testVoidType(FunctionReaderInterface $reader): void
{
$type = $reader->findFunctionType(
function: new \ReflectionFunction('TypeLang\Reader\Tests\Stub\get_void_type'),
);
self::assertSameType(self::builtin('void'), $type);
}
#[DataProvider('readersDataProvider')]
public function testNoReturnTypeHasNoType(FunctionReaderInterface $reader): void
{
$type = $reader->findFunctionType(
function: new \ReflectionFunction('TypeLang\Reader\Tests\Stub\get_no_type'),
);
self::assertNull($type);
}
}