class ComponentTestDoesNotExtendCoreTest
Ensures that no component tests are extending a core test base class.
@implements Rule<\PHPStan\Node\InClassNode>
@internal
Hierarchy
- class \Drupal\PHPStan\Rules\ComponentTestDoesNotExtendCoreTest extends \PHPStan\Rules\Rule
Expanded class hierarchy of ComponentTestDoesNotExtendCoreTest
1 file declares its use of ComponentTestDoesNotExtendCoreTest
- ComponentTestDoesNotExtendCoreTestTest.php in core/
tests/ PHPStan/ tests/ ComponentTestDoesNotExtendCoreTestTest.php
File
-
core/
tests/ PHPStan/ Rules/ ComponentTestDoesNotExtendCoreTest.php, line 26
Namespace
Drupal\PHPStan\RulesView source
final class ComponentTestDoesNotExtendCoreTest implements Rule {
public function __construct(private ReflectionProvider $reflectionProvider) {
}
/**
* {@inheritdoc}
*/
public function getNodeType() : string {
return InClassNode::class;
}
/**
* {@inheritdoc}
*/
public function processNode(Node $node, Scope $scope) : array {
$class = $node->getClassReflection();
if (!str_starts_with($class->getName(), 'Drupal\\Tests\\Component')) {
return [];
}
$invalidParents = [
$this->reflectionProvider
->getClass(UnitTestCase::class),
$this->reflectionProvider
->getClass(BuildTestBase::class),
$this->reflectionProvider
->getClass(KernelTestBase::class),
$this->reflectionProvider
->getClass(BrowserTestBase::class),
];
foreach ($invalidParents as $invalidParent) {
if ($class->isSubclassOfClass($invalidParent)) {
return [
RuleErrorBuilder::message("Component tests should not extend {$invalidParent->getName()}.")
->line($node->getStartLine())
->build(),
];
}
}
return [];
}
}
Members
Title Sort descending | Modifiers | Object type | Summary |
---|---|---|---|
ComponentTestDoesNotExtendCoreTest::getNodeType | public | function | |
ComponentTestDoesNotExtendCoreTest::processNode | public | function | |
ComponentTestDoesNotExtendCoreTest::__construct | public | function |
Buggy or inaccurate documentation? Please file an issue. Need support? Need help programming? Connect with the Drupal community.