Skip to content

Commit 7cb0ec7

Browse files
authored
Fix possibly undefined offset access in tests
1 parent bbe52c7 commit 7cb0ec7

File tree

1 file changed

+31
-23
lines changed

1 file changed

+31
-23
lines changed

tests/PHPStan/Type/UnionTypeTest.php

Lines changed: 31 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -176,20 +176,22 @@ public function testSelfCompare(Type $type): void
176176
*/
177177
public static function dataIsSuperTypeOf(): Iterator
178178
{
179+
$int = new IntegerType();
180+
$string = new StringType();
179181
$unionTypeA = new UnionType([
180-
new IntegerType(),
181-
new StringType(),
182+
$int,
183+
$string,
182184
]);
183185

184186
yield [
185187
$unionTypeA,
186-
$unionTypeA->getTypes()[0],
188+
$int,
187189
TrinaryLogic::createYes(),
188190
];
189191

190192
yield [
191193
$unionTypeA,
192-
$unionTypeA->getTypes()[1],
194+
$string,
193195
TrinaryLogic::createYes(),
194196
];
195197

@@ -259,23 +261,25 @@ public static function dataIsSuperTypeOf(): Iterator
259261
TrinaryLogic::createNo(),
260262
];
261263

264+
$intersectionTypeB = new IntersectionType([
265+
new ObjectType('ArrayObject'),
266+
new IterableType(new MixedType(), new ObjectType('DatePeriod')),
267+
]);
268+
$arrayTypeB = new ArrayType(new MixedType(), new ObjectType('DatePeriod'));
262269
$unionTypeB = new UnionType([
263-
new IntersectionType([
264-
new ObjectType('ArrayObject'),
265-
new IterableType(new MixedType(), new ObjectType('DatePeriod')),
266-
]),
267-
new ArrayType(new MixedType(), new ObjectType('DatePeriod')),
270+
$intersectionTypeB,
271+
$arrayTypeB,
268272
]);
269273

270274
yield [
271275
$unionTypeB,
272-
$unionTypeB->getTypes()[0],
276+
$intersectionTypeB,
273277
TrinaryLogic::createYes(),
274278
];
275279

276280
yield [
277281
$unionTypeB,
278-
$unionTypeB->getTypes()[1],
282+
$arrayTypeB,
279283
TrinaryLogic::createYes(),
280284
];
281285

@@ -473,9 +477,11 @@ public function testIsSuperTypeOf(UnionType $type, Type $otherType, TrinaryLogic
473477
*/
474478
public static function dataIsSubTypeOf(): Iterator
475479
{
480+
$int = new IntegerType();
481+
$string = new StringType();
476482
$unionTypeA = new UnionType([
477-
new IntegerType(),
478-
new StringType(),
483+
$int,
484+
$string,
479485
]);
480486

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

499505
yield [
500506
$unionTypeA,
501-
$unionTypeA->getTypes()[0],
507+
$int,
502508
TrinaryLogic::createMaybe(),
503509
];
504510

505511
yield [
506512
$unionTypeA,
507-
$unionTypeA->getTypes()[1],
513+
$string,
508514
TrinaryLogic::createMaybe(),
509515
];
510516

@@ -562,13 +568,15 @@ public static function dataIsSubTypeOf(): Iterator
562568
TrinaryLogic::createNo(),
563569
];
564570

571+
$intersectionTypeB = new IntersectionType([
572+
new ObjectType('ArrayObject'),
573+
new IterableType(new MixedType(), new ObjectType('Item')),
574+
new CallableType(),
575+
]);
576+
$arrayTypeB = new ArrayType(new MixedType(), new ObjectType('Item'));
565577
$unionTypeB = new UnionType([
566-
new IntersectionType([
567-
new ObjectType('ArrayObject'),
568-
new IterableType(new MixedType(), new ObjectType('Item')),
569-
new CallableType(),
570-
]),
571-
new ArrayType(new MixedType(), new ObjectType('Item')),
578+
$intersectionTypeB,
579+
$arrayTypeB,
572580
]);
573581

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

592600
yield [
593601
$unionTypeB,
594-
$unionTypeB->getTypes()[0],
602+
$intersectionTypeB,
595603
TrinaryLogic::createMaybe(),
596604
];
597605

598606
yield [
599607
$unionTypeB,
600-
$unionTypeB->getTypes()[1],
608+
$arrayTypeB,
601609
TrinaryLogic::createMaybe(),
602610
];
603611

0 commit comments

Comments
 (0)