-
Notifications
You must be signed in to change notification settings - Fork 574
Expand file tree
/
Copy pathLateResolvableTypeTraitTest.php
More file actions
78 lines (69 loc) · 1.92 KB
/
LateResolvableTypeTraitTest.php
File metadata and controls
78 lines (69 loc) · 1.92 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
<?php declare(strict_types = 1);
namespace PHPStan\Type;
use PHPStan\Type\Constant\ConstantStringType;
use PHPStan\TrinaryLogic;
use PHPStan\Type\IntegerType;
use PHPStan\Type\NeverType;
use PHPStan\Type\StringType;
use PHPStan\Type\Type;
use PHPStan\Type\ConditionalTypeForParameter;
use PHPStan\Type\UnionType;
use PHPUnit\Framework\TestCase;
use PHPUnit\Framework\Attributes\DataProvider;
class LateResolvableTypeTraitTest extends TestCase
{
public static function dataIsSuperTypeOf(): array
{
return self::provideCases();
}
public static function dataIsSubTypeOf(): array
{
return self::provideCases();
}
private static function createConditional(
string $parameterName = '$operator',
string $targetLiteral = 'in',
?Type $ifType = null,
?Type $elseType = null,
bool $negated = false,
): ConditionalTypeForParameter
{
return new ConditionalTypeForParameter(
$parameterName,
new ConstantStringType($targetLiteral),
$ifType ?? new IntegerType(),
$elseType ?? new NeverType(),
$negated,
);
}
/**
* @return list<array{Type, Type, TrinaryLogic}>
*/
private static function provideCases(): array
{
return [
'conditional vs same conditional' => [
self::createConditional(),
self::createConditional(),
TrinaryLogic::createYes(),
],
'conditional vs union containing it' => [
self::createConditional(),
new UnionType([new StringType(), self::createConditional()]),
TrinaryLogic::createYes(),
],
];
}
#[DataProvider('dataIsSuperTypeOf')]
public function testIsSuperTypeOf(Type $left, Type $right, TrinaryLogic $expected): void
{
$actual = $left->isSuperTypeOf($right);
$this->assertSame($expected->describe(), $actual->describe());
}
#[DataProvider('dataIsSubTypeOf')]
public function testIsSubTypeOf(Type $left, Type $right, TrinaryLogic $expected): void
{
$actual = $left->isSubTypeOf($right);
$this->assertSame($expected->describe(), $actual->describe());
}
}