Skip to content

Commit ccc0ae2

Browse files
committed
separate test expectations
1 parent a72ae08 commit ccc0ae2

File tree

3 files changed

+21
-11
lines changed

3 files changed

+21
-11
lines changed

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

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,3 +19,12 @@ function doUnmatchedAsNull(string $s): void {
1919
assertType('array{}|array{0: string, 1?: string, 2?: string, 3?: string}', $matches);
2020
}
2121

22+
// see https://3v4l.org/VeDob#veol
23+
function unmatchedAsNullWithOptionalGroup(string $s): void {
24+
if (preg_match('/Price: (£|€)?\d+/', $s, $matches, PREG_UNMATCHED_AS_NULL)) {
25+
assertType('array{0: string, 1?: string}', $matches);
26+
} else {
27+
assertType('array{}', $matches);
28+
}
29+
assertType('array{}|array{0: string, 1?: string}', $matches);
30+
}

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

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,3 +17,15 @@ function doUnmatchedAsNull(string $s): void {
1717
}
1818
assertType('array{}|array{string, string|null, string|null, string|null}', $matches);
1919
}
20+
21+
// see https://3v4l.org/VeDob
22+
function unmatchedAsNullWithOptionalGroup(string $s): void {
23+
if (preg_match('/Price: (£|€)?\d+/', $s, $matches, PREG_UNMATCHED_AS_NULL)) {
24+
// with PREG_UNMATCHED_AS_NULL the offset 1 will always exist. It is correct that it's nullable because it's optional though
25+
assertType('array{string, string|null}', $matches);
26+
} else {
27+
assertType('array{}', $matches);
28+
}
29+
assertType('array{}|array{string, string|null}', $matches);
30+
}
31+

tests/PHPStan/Analyser/nsrt/preg_match_shapes.php

Lines changed: 0 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -353,17 +353,6 @@ function bug11277b(string $value): void
353353
}
354354
}
355355

356-
// see https://3v4l.org/VeDob
357-
function unmatchedAsNullWithOptionalGroup(string $s): void {
358-
if (preg_match('/Price: (£|€)?\d+/', $s, $matches, PREG_UNMATCHED_AS_NULL)) {
359-
// with PREG_UNMATCHED_AS_NULL the offset 1 will always exist. It is correct that it's nullable because it's optional though
360-
assertType('array{string, string|null}', $matches);
361-
} else {
362-
assertType('array{}', $matches);
363-
}
364-
assertType('array{}|array{string, string|null}', $matches);
365-
}
366-
367356
// https://www.pcre.org/current/doc/html/pcre2pattern.html#dupgroupnumber
368357
// https://3v4l.org/09qdT
369358
function bug11291(string $s): void {

0 commit comments

Comments
 (0)