Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
54 changes: 31 additions & 23 deletions tests/PHPStan/Type/UnionTypeTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -176,20 +176,22 @@ public function testSelfCompare(Type $type): void
*/
public static function dataIsSuperTypeOf(): Iterator
{
$int = new IntegerType();
$string = new StringType();
$unionTypeA = new UnionType([
new IntegerType(),
new StringType(),
$int,
$string,
]);

yield [
$unionTypeA,
$unionTypeA->getTypes()[0],
$int,
TrinaryLogic::createYes(),
];

yield [
$unionTypeA,
$unionTypeA->getTypes()[1],
$string,
TrinaryLogic::createYes(),
];

Expand Down Expand Up @@ -259,23 +261,25 @@ public static function dataIsSuperTypeOf(): Iterator
TrinaryLogic::createNo(),
];

$intersectionTypeB = new IntersectionType([
new ObjectType('ArrayObject'),
new IterableType(new MixedType(), new ObjectType('DatePeriod')),
]);
$arrayTypeB = new ArrayType(new MixedType(), new ObjectType('DatePeriod'));
$unionTypeB = new UnionType([
new IntersectionType([
new ObjectType('ArrayObject'),
new IterableType(new MixedType(), new ObjectType('DatePeriod')),
]),
new ArrayType(new MixedType(), new ObjectType('DatePeriod')),
$intersectionTypeB,
$arrayTypeB,
]);

yield [
$unionTypeB,
$unionTypeB->getTypes()[0],
$intersectionTypeB,
TrinaryLogic::createYes(),
];

yield [
$unionTypeB,
$unionTypeB->getTypes()[1],
$arrayTypeB,
TrinaryLogic::createYes(),
];

Expand Down Expand Up @@ -473,9 +477,11 @@ public function testIsSuperTypeOf(UnionType $type, Type $otherType, TrinaryLogic
*/
public static function dataIsSubTypeOf(): Iterator
{
$int = new IntegerType();
$string = new StringType();
$unionTypeA = new UnionType([
new IntegerType(),
new StringType(),
$int,
$string,
]);

yield [
Expand All @@ -498,13 +504,13 @@ public static function dataIsSubTypeOf(): Iterator

yield [
$unionTypeA,
$unionTypeA->getTypes()[0],
$int,
TrinaryLogic::createMaybe(),
];

yield [
$unionTypeA,
$unionTypeA->getTypes()[1],
$string,
TrinaryLogic::createMaybe(),
];

Expand Down Expand Up @@ -562,13 +568,15 @@ public static function dataIsSubTypeOf(): Iterator
TrinaryLogic::createNo(),
];

$intersectionTypeB = new IntersectionType([
new ObjectType('ArrayObject'),
new IterableType(new MixedType(), new ObjectType('Item')),
new CallableType(),
]);
$arrayTypeB = new ArrayType(new MixedType(), new ObjectType('Item'));
$unionTypeB = new UnionType([
new IntersectionType([
new ObjectType('ArrayObject'),
new IterableType(new MixedType(), new ObjectType('Item')),
new CallableType(),
]),
new ArrayType(new MixedType(), new ObjectType('Item')),
$intersectionTypeB,
$arrayTypeB,
]);

yield [
Expand All @@ -591,13 +599,13 @@ public static function dataIsSubTypeOf(): Iterator

yield [
$unionTypeB,
$unionTypeB->getTypes()[0],
$intersectionTypeB,
TrinaryLogic::createMaybe(),
];

yield [
$unionTypeB,
$unionTypeB->getTypes()[1],
$arrayTypeB,
TrinaryLogic::createMaybe(),
];

Expand Down
Loading