-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathMethodReaderTest.php
More file actions
71 lines (60 loc) 路 2.22 KB
/
Copy pathMethodReaderTest.php
File metadata and controls
71 lines (60 loc) 路 2.22 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
<?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\Reader\Tests\Stub\MethodReaderStub;
use TypeLang\Reader\Tests\Stub\MethodReaderStub82;
use TypeLang\Type\IntersectionTypeNode;
use TypeLang\Type\UnionTypeNode;
#[Group('type-lang/reader')]
class MethodReaderTest extends ReaderTestCase
{
#[DataProvider('readersDataProvider')]
public function testSimpleType(FunctionReaderInterface $reader): void
{
$type = $reader->findFunctionType(
function: new \ReflectionMethod(MethodReaderStub::class, 'getSingleType'),
);
self::assertSameType(self::builtin('int'), $type);
}
#[DataProvider('readersDataProvider')]
public function testUnionType(FunctionReaderInterface $reader): void
{
$type = $reader->findFunctionType(
function: new \ReflectionMethod(MethodReaderStub::class, 'getUnionType'),
);
self::assertSameType(new UnionTypeNode([
self::builtin('string'),
self::builtin('int')
]), $type);
}
#[DataProvider('readersDataProvider')]
public function testIntersectionType(FunctionReaderInterface $reader): void
{
$type = $reader->findFunctionType(
function: new \ReflectionMethod(MethodReaderStub::class, 'getIntersectionType'),
);
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
{
$type = $reader->findFunctionType(
function: new \ReflectionMethod(MethodReaderStub82::class, 'getCompositeType'),
);
self::assertSameType(new UnionTypeNode([
new IntersectionTypeNode([
self::classType(\ArrayAccess::class),
self::classType(\Traversable::class)
]),
self::builtin('array')
]), $type);
}
}