Skip to content

Commit 9702612

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

File tree

1 file changed

+31
-2
lines changed

1 file changed

+31
-2
lines changed

tests/PHPStan/Rules/Functions/ParameterCastableToNumberRuleTest.php

Lines changed: 31 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->hackParameterNames([
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,31 @@ 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 hackParameterNames(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+
],
149+
[
150+
'$input of function array_sum',
151+
'$input of function array_product',
152+
],
153+
$error[0],
154+
);
155+
156+
return $error;
157+
}, $errors);
158+
}
159+
131160
}

0 commit comments

Comments
 (0)