Skip to content

Commit 2223acd

Browse files
committed
Add more tests
1 parent 5570289 commit 2223acd

File tree

3 files changed

+37
-4
lines changed

3 files changed

+37
-4
lines changed

tests/PHPStan/Analyser/nsrt/list-type.php

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -106,4 +106,29 @@ public function testUnset(array $list): void
106106
assertType('array<int<0, 1>|int<3, max>, int>', $list);
107107
}
108108

109+
/** @param list<int> $list */
110+
public function testSetOffsetExplicitlyWithoutGap(array $list): void
111+
{
112+
assertType('list<int>', $list);
113+
$list[0] = 17;
114+
assertType('non-empty-list<int>&hasOffsetValue(0, 17)', $list);
115+
$list[1] = 19;
116+
assertType('non-empty-list<int>&hasOffsetValue(0, 17)&hasOffsetValue(1, 19)', $list);
117+
$list[0] = 21;
118+
assertType('non-empty-list<int>&hasOffsetValue(0, 21)&hasOffsetValue(1, 19)', $list);
119+
120+
$list[2] = 23;
121+
assertType('non-empty-array<int<0, max>, int>&hasOffsetValue(0, 21)&hasOffsetValue(1, 19)&hasOffsetValue(2, 23)', $list);
122+
}
123+
124+
/** @param list<int> $list */
125+
public function testSetOffsetExplicitlyWithGap(array $list): void
126+
{
127+
assertType('list<int>', $list);
128+
$list[0] = 17;
129+
assertType('non-empty-list<int>&hasOffsetValue(0, 17)', $list);
130+
$list[2] = 21;
131+
assertType('non-empty-array<int<0, max>, int>&hasOffsetValue(0, 17)&hasOffsetValue(2, 21)', $list);
132+
}
133+
109134
}

tests/PHPStan/Rules/Properties/TypesAssignedToPropertiesRuleTest.php

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -695,7 +695,13 @@ public function testBug11617(): void
695695
public function testBug12131(): void
696696
{
697697
$this->checkExplicitMixed = true;
698-
$this->analyse([__DIR__ . '/data/bug-12131.php'], []);
698+
$this->analyse([__DIR__ . '/data/bug-12131.php'], [
699+
[
700+
'Property Bug12131\Test::$array (non-empty-list<int>) does not accept non-empty-array<int<0, max>, int>.',
701+
29,
702+
'non-empty-array<int<0, max>, int> might not be a list.',
703+
],
704+
]);
699705
}
700706

701707
}

tests/PHPStan/Rules/Properties/data/bug-12131.php

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,9 @@ public function setAtOne(): void
2323
{
2424
$this->array[1] = 1;
2525
}
26-
}
2726

28-
$a = new Test();
29-
$a->setAtOne();
27+
public function setAtTwo(): void
28+
{
29+
$this->array[2] = 1;
30+
}
31+
}

0 commit comments

Comments
 (0)