Skip to content

Commit d25621a

Browse files
committed
Update phpstan tests to latest phpstan features
1 parent deb3871 commit d25621a

File tree

3 files changed

+24
-18
lines changed

3 files changed

+24
-18
lines changed

phpstan-baseline.neon

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,12 @@ parameters:
66
count: 1
77
path: src/PHPStan/PregReplaceCallbackClosureTypeExtension.php
88

9+
-
10+
message: '#^Method Composer\\Pcre\\Preg\:\:split\(\) should return list\<string\> but returns list\<array\{string, int\<0, max\>\}\|string\>\.$#'
11+
identifier: return.type
12+
count: 1
13+
path: src/Preg.php
14+
915
-
1016
message: '#^Parameter \#2 \$callback of function preg_replace_callback expects callable\(array\<string\>\)\: string, \(callable\(array\<int\|string, array\{string\|null, int\<\-1, max\>\}\>\)\: string\)\|\(callable\(array\<int\|string, string\|null\>\)\: string\) given\.$#'
1117
identifier: argument.type

tests/PHPStanTests/nsrt/preg-match.php

Lines changed: 17 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -9,71 +9,71 @@
99
function doMatch(string $s): void
1010
{
1111
if (Preg::match('/Price: /i', $s, $matches)) {
12-
assertType('array{string}', $matches);
12+
assertType('array{non-falsy-string}', $matches);
1313
} else {
1414
assertType('array{}', $matches);
1515
}
16-
assertType('array{}|array{string}', $matches);
16+
assertType('array{}|array{non-falsy-string}', $matches);
1717

1818
if (Preg::match('/Price: (£|€)\d+/', $s, $matches)) {
19-
assertType('array{string, \'£\'|\'\'}', $matches);
19+
assertType('array{non-falsy-string, \'£\'|\'\'}', $matches);
2020
} else {
2121
assertType('array{}', $matches);
2222
}
23-
assertType('array{}|array{string, \'£\'|\'\'}', $matches);
23+
assertType('array{}|array{non-falsy-string, \'£\'|\'\'}', $matches);
2424

2525
if (Preg::match('/Price: (£|€)?\d+/', $s, $matches)) {
26-
assertType('array{string, \'£\'|\'\'|null}', $matches);
26+
assertType('array{non-falsy-string, \'£\'|\'\'|null}', $matches);
2727
} else {
2828
assertType('array{}', $matches);
2929
}
30-
assertType('array{}|array{string, \'£\'|\'\'|null}', $matches);
30+
assertType('array{}|array{non-falsy-string, \'£\'|\'\'|null}', $matches);
3131

3232
// passing the PREG_UNMATCHED_AS_NULL should change nothing compared to above as it is always set
3333
if (Preg::match('/Price: (£|€)?\d+/', $s, $matches, PREG_UNMATCHED_AS_NULL)) {
34-
assertType('array{string, \'£\'|\'\'|null}', $matches);
34+
assertType('array{non-falsy-string, \'£\'|\'\'|null}', $matches);
3535
} else {
3636
assertType('array{}', $matches);
3737
}
38-
assertType('array{}|array{string, \'£\'|\'\'|null}', $matches);
38+
assertType('array{}|array{non-falsy-string, \'£\'|\'\'|null}', $matches);
3939

4040
if (Preg::isMatch('/Price: (?<currency>£|€)\d+/', $s, $matches)) {
41-
assertType('array{0: string, currency: \'£\'|\'\', 1: \'£\'|\'\'}', $matches);
41+
assertType('array{0: non-falsy-string, currency: \'£\'|\'\', 1: \'£\'|\'\'}', $matches);
4242
} else {
4343
assertType('array{}', $matches);
4444
}
45-
assertType('array{}|array{0: string, currency: \'£\'|\'\', 1: \'£\'|\'\'}', $matches);
45+
assertType('array{}|array{0: non-falsy-string, currency: \'£\'|\'\', 1: \'£\'|\'\'}', $matches);
4646
}
4747

4848
function doMatchStrictGroups(string $s): void
4949
{
5050
if (Preg::matchStrictGroups('/Price: /i', $s, $matches)) {
51-
assertType('array{string}', $matches);
51+
assertType('array{non-falsy-string}', $matches);
5252
} else {
5353
assertType('array{}', $matches);
5454
}
55-
assertType('array{}|array{string}', $matches);
55+
assertType('array{}|array{non-falsy-string}', $matches);
5656

5757
if (Preg::matchStrictGroups('/Price: (£|€)\d+/', $s, $matches)) {
58-
assertType('array{string, \'£\'|\'\'}', $matches);
58+
assertType('array{non-falsy-string, \'£\'|\'\'}', $matches);
5959
} else {
6060
assertType('array{}', $matches);
6161
}
62-
assertType('array{}|array{string, \'£\'|\'\'}', $matches);
62+
assertType('array{}|array{non-falsy-string, \'£\'|\'\'}', $matches);
6363

6464
if (Preg::isMatchStrictGroups('/Price: (?<test>£|€)\d+/', $s, $matches)) {
65-
assertType('array{0: string, test: \'£\'|\'\', 1: \'£\'|\'\'}', $matches);
65+
assertType('array{0: non-falsy-string, test: \'£\'|\'\', 1: \'£\'|\'\'}', $matches);
6666
} else {
6767
assertType('array{}', $matches);
6868
}
69-
assertType('array{}|array{0: string, test: \'£\'|\'\', 1: \'£\'|\'\'}', $matches);
69+
assertType('array{}|array{0: non-falsy-string, test: \'£\'|\'\', 1: \'£\'|\'\'}', $matches);
7070
}
7171

7272
function doMatchStrictGroupsUnsafe(string $s): void
7373
{
7474
if (Preg::isMatchStrictGroups('{Configure Command(?: *</td><td class="v">| *=> *)(.*)(?:</td>|$)}m', $s, $matches)) {
7575
// does not error because the match group might be empty but is not optional
76-
assertType('array{string, string}', $matches);
76+
assertType('array{non-falsy-string, string}', $matches);
7777
}
7878

7979
// should error as it is unsafe due to the optional group 1

tests/PHPStanTests/nsrt/preg-replace-callback.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@ function (string $s): void {
3030
Preg::replaceCallback(
3131
'|<p>(\s*)\w|',
3232
function ($matches) {
33-
assertType('array{string, string}', $matches);
33+
assertType('array{non-falsy-string, string}', $matches);
3434
return '';
3535
},
3636
$s

0 commit comments

Comments
 (0)