Skip to content

Commit c96736b

Browse files
committed
feat: add test for Error
1 parent b809edc commit c96736b

File tree

1 file changed

+15
-1
lines changed

1 file changed

+15
-1
lines changed

tests/PHPStan/Analyser/nsrt/preg_split.php

Lines changed: 15 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,9 +6,10 @@
66

77
class HelloWorld
88
{
9+
private const NUMERIC_STRING_1 = "1";
10+
private const NUMERIC_STRING_NEGATIVE_1 = "-1";
911
public function doFoo()
1012
{
11-
assertType('*ERROR*', preg_split('/[0-9a]', '1-2-3'));
1213
assertType("array{''}", preg_split('/-/', ''));
1314
assertType("array{}", preg_split('/-/', '', -1, PREG_SPLIT_NO_EMPTY));
1415
assertType("array{'1', '-', '2', '-', '3'}", preg_split('/ *(-) */', '1- 2-3', -1, PREG_SPLIT_DELIM_CAPTURE));
@@ -21,6 +22,19 @@ public function doFoo()
2122
assertType("array{array{'1', 0}, array{'2', 2}, array{'3', 4}}", preg_split('/-/', '1-2-3', -1, PREG_SPLIT_NO_EMPTY | PREG_SPLIT_OFFSET_CAPTURE));
2223
assertType("array{array{'1', 0}, array{'', 2}, array{'3', 3}}", preg_split('/-/', '1--3', -1, PREG_SPLIT_OFFSET_CAPTURE));
2324
assertType("array{array{'1', 0}, array{'3', 3}}", preg_split('/-/', '1--3', -1, PREG_SPLIT_NO_EMPTY | PREG_SPLIT_OFFSET_CAPTURE));
25+
26+
assertType("array{'1', '2', '3'}", preg_split('/-/', '1-2-3', self::NUMERIC_STRING_NEGATIVE_1));
27+
assertType("array{'1', '2', '3'}", preg_split('/-/', '1-2-3', -1, self::NUMERIC_STRING_1));
28+
}
29+
30+
public function doWithError() {
31+
assertType('*ERROR*', preg_split('/[0-9a]', '1-2-3'));
32+
assertType('*ERROR*', preg_split('/-/', '1-2-3', 'hogehoge'));
33+
assertType('*ERROR*', preg_split('/-/', '1-2-3', -1, 'hogehoge'));
34+
assertType('*ERROR*', preg_split('/-/', '1-2-3', [], self::NUMERIC_STRING_NEGATIVE_1));
35+
assertType('*ERROR*', preg_split('/-/', '1-2-3', null, self::NUMERIC_STRING_NEGATIVE_1));
36+
assertType('*ERROR*', preg_split('/-/', '1-2-3', -1, []));
37+
assertType('*ERROR*', preg_split('/-/', '1-2-3', -1, null));
2438
}
2539

2640
public function doWithVariables(string $pattern, string $subject, int $offset, int $flags): void

0 commit comments

Comments
 (0)