reflectionProvider = $reflectionProvider;
$this->visibilityManipulator = $visibilityManipulator;
}
public function getRuleDefinition() : RuleDefinition
{
return new RuleDefinition('PHPUnit test case will be finalized', [new CodeSample(<<<'CODE_SAMPLE'
use PHPUnit\Framework\TestCase;
class SomeClass extends TestCase
{
}
CODE_SAMPLE
, <<<'CODE_SAMPLE'
use PHPUnit\Framework\TestCase;
final class SomeClass extends TestCase
{
}
CODE_SAMPLE
)]);
}
/**
* @return array>
*/
public function getNodeTypes() : array
{
return [Class_::class];
}
/**
* @param Class_ $node
*/
public function refactor(Node $node) : ?Node
{
// skip obvious cases
if ($node->isAbstract() || $node->isAnonymous() || $node->isFinal()) {
return null;
}
$className = $this->getName($node);
if (!\is_string($className)) {
return null;
}
if (\substr_compare($className, 'TestCase', -\strlen('TestCase')) === 0) {
return null;
}
if (!$this->reflectionProvider->hasClass($className)) {
return null;
}
$classReflection = $this->reflectionProvider->getClass($className);
if (!$classReflection->isSubclassOf('PHPUnit\\Framework\\TestCase')) {
return null;
}
if ($node->attrGroups !== []) {
$node->setAttribute(AttributeKey::ORIGINAL_NODE, null);
}
$this->visibilityManipulator->makeFinal($node);
return $node;
}
}