-
What language is this for? PHP
-
Which rule? php:s2187
-
Why do you believe it’s a false-positive/false-negative?
When creating a configurable Abstract test case and then just using different sub-classes, class should not be reported as not containing any tests. When phpunit runs, all test methods from the hierarchy are also run.- SonarQube - which version? Enterprise Edition Version 9.9.4 (build 87374)
-
How can we reproduce the problem? Give us a self-contained snippet of code (formatted text, no screenshots)
abstract class AbstractTestCases extends TestCase
{
abstract protected function createSystemUnderTest(): mixed;
public function testInstanciatedSystemUnderTestPassesTest(): void
{
$sut = $this->createSystemUnderTest();
// perform as many assertions as needed
self::assertInstanceOf(MySpecificExpectation::class, $sut);
}
}
class MyConcreteTest extends AbstractTestCases
{
protected function createSystemUnderTest(): MyConcrete
{
return new MyConcrete();
}
}
In the above example, SonarQube complains about MyConcreteTest not having any tests, which is false.
I tried to move testing methods inside a trait used in MyConcreteTest but the class is still marked as not having any tests which is clearly not the case.