forked from phpstan/phpstan-src
-
Notifications
You must be signed in to change notification settings - Fork 0
/
IntegerRangeTypeTest.php
75 lines (62 loc) · 1.7 KB
/
IntegerRangeTypeTest.php
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
<?php declare(strict_types = 1);
namespace PHPStan\Type;
use PHPStan\TrinaryLogic;
use PHPStan\Type\Constant\ConstantIntegerType;
class IntegerRangeTypeTest extends \PHPStan\Testing\TestCase
{
public function dataIsSubTypeOf(): iterable
{
yield [
IntegerRangeType::fromInterval(5, 10),
new IntegerType(),
TrinaryLogic::createYes(),
];
yield [
IntegerRangeType::fromInterval(5, 10),
new ConstantIntegerType(10),
TrinaryLogic::createMaybe(),
];
yield [
IntegerRangeType::fromInterval(5, 10),
new ConstantIntegerType(20),
TrinaryLogic::createNo(),
];
yield [
IntegerRangeType::fromInterval(5, 10),
IntegerRangeType::fromInterval(0, 15),
TrinaryLogic::createYes(),
];
yield [
IntegerRangeType::fromInterval(5, 10),
IntegerRangeType::fromInterval(6, 9),
TrinaryLogic::createMaybe(),
];
yield [
IntegerRangeType::fromInterval(5, 10),
new UnionType([new IntegerType(), new StringType()]),
TrinaryLogic::createYes(),
];
yield [
IntegerRangeType::fromInterval(5, 10),
new UnionType([new ConstantIntegerType(5), IntegerRangeType::fromInterval(6, 10), new StringType()]),
TrinaryLogic::createYes(),
];
yield [
IntegerRangeType::fromInterval(5, 10),
new StringType(),
TrinaryLogic::createNo(),
];
}
/**
* @dataProvider dataIsSubTypeOf
*/
public function testIsSubTypeOf(IntegerRangeType $type, Type $otherType, TrinaryLogic $expectedResult): void
{
$actualResult = $type->isSubTypeOf($otherType);
$this->assertSame(
$expectedResult->describe(),
$actualResult->describe(),
sprintf('%s -> isSuperTypeOf(%s)', $type->describe(VerbosityLevel::precise()), $otherType->describe(VerbosityLevel::precise()))
);
}
}