Skip to content

Commit 97ed353

Browse files
committed
add test case for nonEmptySubject
1 parent 05ac909 commit 97ed353

File tree

1 file changed

+19
-9
lines changed

1 file changed

+19
-9
lines changed

tests/PHPStan/Analyser/nsrt/preg_split.php

Lines changed: 19 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -23,19 +23,11 @@ public function doFoo()
2323
assertType("array{array{'1', 0}, array{'3', 3}}", preg_split('/-/', '1--3', -1, PREG_SPLIT_NO_EMPTY | PREG_SPLIT_OFFSET_CAPTURE));
2424
}
2525

26-
/**
27-
* @param non-empty-string $nonEmptySubject
28-
*/
29-
public function doWithVariables(string $pattern, string $subject, string $nonEmptySubject, int $offset, int $flags): void
26+
public function doWithVariables(string $pattern, string $subject, int $offset, int $flags): void
3027
{
3128
assertType('(list<array{string, int<0, max>}|string>|false)', preg_split($pattern, $subject, $offset, $flags));
3229
assertType('(list<array{string, int<0, max>}|string>|false)', preg_split("//", $subject, $offset, $flags));
3330

34-
assertType('(non-empty-list<array{string, int<0, max>}|string>|false)', preg_split($pattern, $nonEmptySubject, $offset, $flags));
35-
assertType('(non-empty-list<array{string, int<0, max>}|string>|false)', preg_split("//", $nonEmptySubject, $offset, $flags));
36-
37-
assertType('(non-empty-list<string>|false)', preg_split("//", $nonEmptySubject));
38-
3931
assertType('(non-empty-list<array{string, int<0, max>}|string>|false)', preg_split($pattern, "1-2-3", $offset, $flags));
4032
assertType('(list<array{string, int<0, max>}|string>|false)', preg_split($pattern, $subject, -1, $flags));
4133
assertType('(list<non-empty-string>|false)', preg_split($pattern, $subject, $offset, PREG_SPLIT_NO_EMPTY));
@@ -44,6 +36,24 @@ public function doWithVariables(string $pattern, string $subject, string $nonEmp
4436
assertType('(list<array{string, int<0, max>}>|false)', preg_split($pattern, $subject, $offset, PREG_SPLIT_DELIM_CAPTURE | PREG_SPLIT_OFFSET_CAPTURE));
4537
}
4638

39+
/**
40+
* @param non-empty-string $nonEmptySubject
41+
*/
42+
public function doWithNonEmptySubject(string $pattern, string $nonEmptySubject, int $offset, int $flags): void
43+
{
44+
assertType('(non-empty-list<string>|false)', preg_split("//", $nonEmptySubject));
45+
46+
assertType('(non-empty-list<array{string, int<0, max>}|string>|false)', preg_split($pattern, $nonEmptySubject, $offset, $flags));
47+
assertType('(non-empty-list<array{string, int<0, max>}|string>|false)', preg_split("//", $nonEmptySubject, $offset, $flags));
48+
49+
assertType('(non-empty-list<array{string, int<0, max>}>|false)', preg_split("/-/", $nonEmptySubject, $offset, PREG_SPLIT_OFFSET_CAPTURE));
50+
assertType('(non-empty-list<non-empty-string>|false)', preg_split("/-/", $nonEmptySubject, $offset, PREG_SPLIT_NO_EMPTY));
51+
assertType('(non-empty-list<string>|false)', preg_split("/-/", $nonEmptySubject, $offset, PREG_SPLIT_DELIM_CAPTURE));
52+
assertType('(non-empty-list<array{string, int<0, max>}>|false)', preg_split("/-/", $nonEmptySubject, $offset, PREG_SPLIT_DELIM_CAPTURE | PREG_SPLIT_OFFSET_CAPTURE));
53+
assertType('(non-empty-list<array{non-empty-string, int<0, max>}>|false)', preg_split("/-/", $nonEmptySubject, $offset, PREG_SPLIT_NO_EMPTY | PREG_SPLIT_OFFSET_CAPTURE));
54+
assertType('(non-empty-list<non-empty-string>|false)', preg_split("/-/", $nonEmptySubject, $offset, PREG_SPLIT_NO_EMPTY | PREG_SPLIT_DELIM_CAPTURE));
55+
}
56+
4757
/**
4858
* @param string $pattern
4959
* @param string $subject

0 commit comments

Comments
 (0)