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:
<?php
use PHPUnit\Framework\Attributes\Test;
use PHPUnit\Framework\TestCase;
class MyTest extends TestCase
{
#[Test]
public function it_not_should_report_tests_are_missing(): void
{
self::assertTrue(true);
}
}