function ComponentTestDoesNotExtendCoreTest::processNode

File

core/tests/PHPStan/Rules/ComponentTestDoesNotExtendCoreTest.php, line 37

Class

ComponentTestDoesNotExtendCoreTest
Ensures that no component tests are extending a core test base class.

Namespace

Drupal\PHPStan\Rules

Code

public function processNode(Node $node, Scope $scope) : array {
    $class = $node->getClassReflection();
    if (!str_starts_with($class->getName(), 'Drupal\\Tests\\Component')) {
        return [];
    }
    $invalidParents = [
        UnitTestCase::class,
        BuildTestBase::class,
        KernelTestBase::class,
        BrowserTestBase::class,
    ];
    foreach ($invalidParents as $invalidParent) {
        if ($class->isSubclassOf($invalidParent)) {
            return [
                RuleErrorBuilder::message("Component tests should not extend {$invalidParent}.")->line($node->getStartLine())
                    ->build(),
            ];
        }
    }
    return [];
}

Buggy or inaccurate documentation? Please file an issue. Need support? Need help programming? Connect with the Drupal community.