Skip to content

Commit 127f8ec

Browse files
committed
test constant strings
1 parent 2a1c9e0 commit 127f8ec

File tree

2 files changed

+20
-5
lines changed

2 files changed

+20
-5
lines changed

tests/PHPStan/Rules/Arrays/NonexistentOffsetInArrayDimFetchRuleTest.php

Lines changed: 13 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -781,25 +781,33 @@ public function testBug11946(): void
781781
'Offset -1 does not exist on string.',
782782
25,
783783
],
784+
[
785+
"Offset 10 does not exist on 'hi'.",
786+
29,
787+
],
784788
[
785789
'Offset int<-5, 5> might not exist on string.',
786-
45,
790+
49,
787791
],
788792
[
789793
'Offset int<-5, 5> might not exist on numeric-string.',
790-
46,
794+
50,
791795
],
792796
[
793797
'Offset int<-5, 5> might not exist on non-empty-string.',
794-
47,
798+
51,
795799
],
796800
[
797801
'Offset int<-5, 5> might not exist on non-falsy-string.',
798-
48,
802+
52,
799803
],
800804
[
801805
'Offset int<-5, 5> might not exist on string.',
802-
49,
806+
53,
807+
],
808+
[
809+
"Offset int<-5, 5> might not exist on 'hi'.",
810+
56,
803811
],
804812
]);
805813
}

tests/PHPStan/Rules/Arrays/data/bug-11946.php

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,10 @@ public function nonExistentStringOffset(
2323
echo $nonEmpty[-1];
2424
echo $nonFalsy[-1];
2525
echo $lowerCase[-1];
26+
27+
$s = 'hi';
28+
echo $s[1];
29+
echo $s[10];
2630
}
2731

2832
/**
@@ -47,5 +51,8 @@ public function maybeNonExistentStringOffset(
4751
echo $nonEmpty[$maybeWrong];
4852
echo $nonFalsy[$maybeWrong];
4953
echo $lowerCase[$maybeWrong];
54+
55+
$s = 'hi';
56+
echo $s[$maybeWrong];
5057
}
5158
}

0 commit comments

Comments
 (0)