Skip to content

Commit 4620350

Browse files
committed
move tests which got php version sensitive
1 parent fd3c3ec commit 4620350

File tree

3 files changed

+17
-8
lines changed

3 files changed

+17
-8
lines changed

tests/PHPStan/Analyser/nsrt/bug-11311-php72.php

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,9 +4,18 @@
44

55
use function PHPStan\Testing\assertType;
66

7+
// on PHP < 7.4, unmatched-as-null does not return null values; see https://3v4l.org/v3HE4
8+
79
function doFoo(string $s) {
810
if (1 === preg_match('/(?<major>\d+)\.(?<minor>\d+)(?:\.(?<patch>\d+))?/', $s, $matches, PREG_UNMATCHED_AS_NULL)) {
9-
// on PHP < 7.4, unmatched-as-null does not return null values; see https://3v4l.org/v3HE4
1011
assertType('array{0: string, major: string, 1: string, minor: string, 2: string, patch?: string, 3?: string}', $matches);
1112
}
1213
}
14+
15+
function doUnmatchedAsNull(string $s): void {
16+
if (preg_match('/(foo)?(bar)?(baz)?/', $s, $matches, PREG_UNMATCHED_AS_NULL)) {
17+
assertType('array{0: string, 1?: string, 2?: string, 3?: string}', $matches);
18+
}
19+
assertType('array{}|array{0: string, 1?: string, 2?: string, 3?: string}', $matches);
20+
}
21+

tests/PHPStan/Analyser/nsrt/bug-11311.php

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,3 +10,10 @@ function doFoo(string $s) {
1010
assertType('array{0: string, major: string|null, 1: string|null, minor: string|null, 2: string|null, patch: string|null, 3: string|null}', $matches);
1111
}
1212
}
13+
14+
function doUnmatchedAsNull(string $s): void {
15+
if (preg_match('/(foo)?(bar)?(baz)?/', $s, $matches, PREG_UNMATCHED_AS_NULL)) {
16+
assertType('array{string, string|null, string|null, string|null}', $matches);
17+
}
18+
assertType('array{}|array{string, string|null, string|null, string|null}', $matches);
19+
}

tests/PHPStan/Analyser/nsrt/preg_match_shapes.php

Lines changed: 0 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -116,13 +116,6 @@ function doOffsetCapture(string $s): void {
116116
assertType('array{}|array{array{string, int<0, max>}, array{string, int<0, max>}, array{string, int<0, max>}, array{string, int<0, max>}}', $matches);
117117
}
118118

119-
function doUnmatchedAsNull(string $s): void {
120-
if (preg_match('/(foo)?(bar)?(baz)?/', $s, $matches, PREG_UNMATCHED_AS_NULL)) {
121-
assertType('array{0: string, 1?: string|null, 2?: string|null, 3?: string|null}', $matches);
122-
}
123-
assertType('array{}|array{0: string, 1?: string|null, 2?: string|null, 3?: string|null}', $matches);
124-
}
125-
126119
function doUnknownFlags(string $s, int $flags): void {
127120
if (preg_match('/(foo)(bar)(baz)/xyz', $s, $matches, $flags)) {
128121
assertType('array<array{string|null, int<-1, max>}|string|null>', $matches);

0 commit comments

Comments
 (0)