function TestClassMethodMetadata::processNode
File
-
core/
tests/ PHPStan/ Rules/ TestClassMethodMetadata.php, line 79
Class
- TestClassMethodMetadata
- Validates method-level PHPUnit test metadata in test classes.
Namespace
Drupal\PHPStan\RulesCode
public function processNode(Node $node, Scope $scope) : array {
$class = $node->getClassReflection();
// We only process PHPUnit test classes here.
if (!$class->isSubclassOfClass($this->reflectionProvider
->getClass(TestCase::class))) {
return [];
}
$method = $node->getMethodReflection();
// Resolve the method's PHPDoc.
$resolvedPhpDoc = $this->fileTypeMapper
->getResolvedPhpDoc($scope->getFile(), $scope->isInClass() ? $scope->getClassReflection()
->getName() : NULL, $scope->isInTrait() ? $scope->getTraitReflection()
->getName() : NULL, $method->getName(), $method->getDocComment() ?? '');
$fails = [];
// Test methods should no longer have PHPUnit metadata annotations.
if ($resolvedPhpDoc) {
foreach ($resolvedPhpDoc->getPhpDocNodes() as $phpDocNode) {
foreach ($phpDocNode->getTags() as $tag) {
if (in_array($tag->name, $this->annotationTargets, TRUE)) {
$fails[] = RuleErrorBuilder::message("Test method {$method->getName()} must not add annotation {$tag->name}.")
->identifier('testMethod.metadataForbidden')
->line($node->getStartLine())
->build();
}
}
}
}
return $fails;
}
Buggy or inaccurate documentation? Please file an issue. Need support? Need help programming? Connect with the Drupal community.