Skip to content

Commit 9963fa9

Browse files
staabmclxmstaab
authored andcommitted
test constant strings
1 parent be60a88 commit 9963fa9

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
@@ -807,25 +807,33 @@ public function testBug11946(): void
807807
'Offset -1 does not exist on string.',
808808
25,
809809
],
810+
[
811+
"Offset 10 does not exist on 'hi'.",
812+
29,
813+
],
810814
[
811815
'Offset int<-5, 5> might not exist on string.',
812-
45,
816+
49,
813817
],
814818
[
815819
'Offset int<-5, 5> might not exist on numeric-string.',
816-
46,
820+
50,
817821
],
818822
[
819823
'Offset int<-5, 5> might not exist on non-empty-string.',
820-
47,
824+
51,
821825
],
822826
[
823827
'Offset int<-5, 5> might not exist on non-falsy-string.',
824-
48,
828+
52,
825829
],
826830
[
827831
'Offset int<-5, 5> might not exist on string.',
828-
49,
832+
53,
833+
],
834+
[
835+
"Offset int<-5, 5> might not exist on 'hi'.",
836+
56,
829837
],
830838
]);
831839
}

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)