"TestCases should contain tests" is triggered when using phpunit 10 Attributes

In PHP 8 the concept of Attributes (similar to Java Annotations) was introduced.

Phpunit adopted those with version 10.

We recently upgrade to phpunit 10 and also changed the @test-phpdoc to the specified #[Test] attribute.

Unfortunately Sonar PHP (on our SonarQube version 10.0, build 68432) doesn’t seem to understand those attributes and reports we have no tests in the various test-files.

I.e. we get a Blocker-issue for each test file from rule php:S2187 with the message “Add some tests to this class.”

A PHP test script with this content should trigger the warning:


use PHPUnit\Framework\Attributes\Test;
use PHPUnit\Framework\TestCase;

class MyTest extends TestCase
    public function it_not_should_report_tests_are_missing(): void

Hello @Arjenm,

thanks a lot for the report. Indeed, for this rule, we miss taking attributes into account. I created this ticket which will adapt the rule implementation. It will be tackled in the next iteration.