Skip to content

Commit 11a974f

Browse files
committed
fix tests for PHP 7.4
1 parent 2f785ba commit 11a974f

File tree

1 file changed

+33
-2
lines changed

1 file changed

+33
-2
lines changed

tests/PHPStan/Rules/Functions/ParameterCastableToNumberRuleTest.php

Lines changed: 33 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,8 @@
66
use PHPStan\Rules\Rule;
77
use PHPStan\Rules\RuleLevelHelper;
88
use PHPStan\Testing\RuleTestCase;
9+
use function array_map;
10+
use function str_replace;
911
use const PHP_VERSION_ID;
1012

1113
/**
@@ -22,7 +24,7 @@ protected function getRule(): Rule
2224

2325
public function testRule(): void
2426
{
25-
$this->analyse([__DIR__ . '/data/param-castable-to-number-functions.php'], [
27+
$this->analyse([__DIR__ . '/data/param-castable-to-number-functions.php'], $this->hackPhp74ErrorMessages([
2628
[
2729
'Parameter #1 $array of function array_sum expects an array of values castable to number, array<int, array<int, int>> given.',
2830
20,
@@ -71,7 +73,7 @@ public function testRule(): void
7173
'Parameter #1 $array of function array_product expects an array of values castable to number, array<int, ParamCastableToNumberFunctions\\ClassWithToString> given.',
7274
32,
7375
],
74-
]);
76+
]));
7577
}
7678

7779
public function testNamedArguments(): void
@@ -128,4 +130,33 @@ public function testBug11883(): void
128130
]);
129131
}
130132

133+
/**
134+
* @param list<array{0: string, 1: int, 2?: string|null}> $errors
135+
* @return list<array{0: string, 1: int, 2?: string|null}>
136+
*/
137+
private function hackPhp74ErrorMessages(array $errors): array
138+
{
139+
if (PHP_VERSION_ID >= 80000) {
140+
return $errors;
141+
}
142+
143+
return array_map(static function (array $error): array {
144+
$error[0] = str_replace(
145+
[
146+
'$array of function array_sum',
147+
'$array of function array_product',
148+
'array<int, CurlHandle>',
149+
],
150+
[
151+
'$input of function array_sum',
152+
'$input of function array_product',
153+
'array<int, resource>',
154+
],
155+
$error[0],
156+
);
157+
158+
return $error;
159+
}, $errors);
160+
}
161+
131162
}

0 commit comments

Comments
 (0)