Skip to content

Commit 534694d

Browse files
committed
fix arg trimming
1 parent daf978e commit 534694d

File tree

1 file changed

+16
-6
lines changed

1 file changed

+16
-6
lines changed

src/Rules/PHPUnit/DataProviderDataRule.php

Lines changed: 16 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -84,10 +84,20 @@ public function processNode(Node $node, Scope $scope): array
8484
return [];
8585
}
8686

87-
$maxNumberOfParameters = 0;
88-
$trimArgs = count($testsWithProvider) > 1;
89-
foreach ($testsWithProvider as $testMethod) {
90-
$maxNumberOfParameters = max($maxNumberOfParameters, $testMethod->getNumberOfParameters());
87+
$trimArgs = false;
88+
if (count($testsWithProvider) > 1) {
89+
$maxNumberOfParameters = $testsWithProvider[0]->getNumberOfParameters();
90+
foreach ($testsWithProvider as $testMethod) {
91+
if ($testMethod->isVariadic()) {
92+
$trimArgs = true;
93+
break;
94+
}
95+
96+
if ($maxNumberOfParameters !== $testMethod->getNumberOfParameters()) {
97+
$trimArgs = true;
98+
break;
99+
}
100+
}
91101
}
92102

93103
foreach ($testsWithProvider as $testMethod) {
@@ -99,8 +109,8 @@ public function processNode(Node $node, Scope $scope): array
99109
continue;
100110
}
101111

102-
if ($trimArgs && $maxNumberOfParameters !== $numberOfParameters) {
103-
$args = array_slice($args, 0, min($numberOfParameters, $maxNumberOfParameters));
112+
if (!$testMethod->isVariadic() && $trimArgs) {
113+
$args = array_slice($args, 0, $numberOfParameters);
104114
}
105115

106116
$scope->invokeNodeCallback(new Node\Expr\MethodCall(

0 commit comments

Comments
 (0)