diff --git a/src/Rules/PHPUnit/DataProviderDataRule.php b/src/Rules/PHPUnit/DataProviderDataRule.php index ce99467..ac800f5 100644 --- a/src/Rules/PHPUnit/DataProviderDataRule.php +++ b/src/Rules/PHPUnit/DataProviderDataRule.php @@ -58,18 +58,13 @@ public function processNode(Node $node, Scope $scope): array return []; } - $arraysTypes = $this->buildArrayTypesFromNode($node, $scope); - if ($arraysTypes === []) { - return []; - } - - $method = $scope->getFunction(); $classReflection = $scope->getClassReflection(); if ($classReflection === null) { return []; } $testsWithProvider = []; + $method = $scope->getFunction(); $testMethods = $this->testMethodsHelper->getTestMethods($classReflection, $scope); foreach ($testMethods as $testMethod) { foreach ($this->dataProviderHelper->getDataProviderMethods($scope, $testMethod, $classReflection) as [, $providerMethodName]) { @@ -84,6 +79,11 @@ public function processNode(Node $node, Scope $scope): array return []; } + $arraysTypes = $this->buildArrayTypesFromNode($node, $scope); + if ($arraysTypes === []) { + return []; + } + $maxNumberOfParameters = null; foreach ($testsWithProvider as $testMethod) { $num = $testMethod->getNumberOfParameters(); diff --git a/src/Rules/PHPUnit/TestMethodsHelper.php b/src/Rules/PHPUnit/TestMethodsHelper.php index f7eff08..f1efc97 100644 --- a/src/Rules/PHPUnit/TestMethodsHelper.php +++ b/src/Rules/PHPUnit/TestMethodsHelper.php @@ -48,11 +48,12 @@ public function getTestMethodReflection(ClassReflection $classReflection, Method */ public function getTestMethods(ClassReflection $classReflection, Scope $scope): array { - if (array_key_exists($classReflection->getName(), $this->methodCache)) { - return $this->methodCache[$classReflection->getName()]; + $className = $classReflection->getName(); + if (array_key_exists($className, $this->methodCache)) { + return $this->methodCache[$className]; } if (!$classReflection->is(TestCase::class)) { - return $this->methodCache[$classReflection->getName()] = []; + return $this->methodCache[$className] = []; } $testMethods = []; @@ -70,7 +71,7 @@ public function getTestMethods(ClassReflection $classReflection, Scope $scope): if ($docComment !== null) { $methodPhpDoc = $this->fileTypeMapper->getResolvedPhpDoc( $scope->getFile(), - $classReflection->getName(), + $className, $scope->isInTrait() ? $scope->getTraitReflection()->getName() : null, $reflectionMethod->getName(), $docComment, @@ -94,7 +95,7 @@ public function getTestMethods(ClassReflection $classReflection, Scope $scope): $testMethods[] = $reflectionMethod; } - return $this->methodCache[$classReflection->getName()] = $testMethods; + return $this->methodCache[$className] = $testMethods; } private function hasTestAnnotation(?ResolvedPhpDocBlock $phpDoc): bool