Skip to content

Commit fce5dfd

Browse files
committed
add: add test for scaler value
1 parent c206ccc commit fce5dfd

File tree

1 file changed

+11
-0
lines changed

1 file changed

+11
-0
lines changed

tests/PHPStan/Analyser/nsrt/preg_split.php

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ class HelloWorld
88
{
99
private const NUMERIC_STRING_1 = "1";
1010
private const NUMERIC_STRING_NEGATIVE_1 = "-1";
11+
1112
public function doFoo()
1213
{
1314
assertType("array{''}", preg_split('/-/', ''));
@@ -39,6 +40,9 @@ public function doWithError() {
3940

4041
public function doWithVariables(string $pattern, string $subject, int $offset, int $flags): void
4142
{
43+
assertType("array{'1', '2', '3'}|array{'1-2-3'}", preg_split('/-/', '1-2-3', $this->generate()));
44+
assertType("array{'1', '2', '3'}|array{'1-2-3'}", preg_split('/-/', '1-2-3', $this->generate(), $this->generate()));
45+
4246
assertType('list<array{string, int<0, max>}|string>|false', preg_split($pattern, $subject, $offset, $flags));
4347
assertType('list<array{string, int<0, max>}|string>|false', preg_split("//", $subject, $offset, $flags));
4448

@@ -50,6 +54,13 @@ public function doWithVariables(string $pattern, string $subject, int $offset, i
5054
assertType('list<array{string, int<0, max>}>|false', preg_split($pattern, $subject, $offset, PREG_SPLIT_DELIM_CAPTURE | PREG_SPLIT_OFFSET_CAPTURE));
5155
}
5256

57+
/**
58+
* @return 1|'17'
59+
*/
60+
private function generate(): int|string {
61+
return (rand() % 2 === 0) ? 1 : "17";
62+
}
63+
5364
/**
5465
* @param non-empty-string $nonEmptySubject
5566
*/

0 commit comments

Comments
 (0)