The assertion is not recognized when executed by a closure defined in a data provider. Executing the test via phpunit shows an assertion has been executed.
Testfile
<?php
namespace CWS\Tests\Unit\CWS;
use PHPUnit\Framework\TestCase;
use PHPUnit\Framework\Attributes\DataProvider;
class SonarTest extends TestCase
{
public static function provider_testAssertion(): iterable
{
return [
[
'callback' => function () {
// This is not recognized by SonarQube.
$this->assertTrue(true);
},
],
];
}
#[DataProvider('provider_testAssertion')]
public function testAssertion(callable $callback): void
{
$callback->call($this);
}
}
Executing the tests via command line shows 1 assertion.
$ phpunit Tests/Unit/CWS/SonarTest.php
PHPUnit 11.5.45 by Sebastian Bergmann and contributors.
Runtime: PHP 8.3.32
Configuration: /var/www/html/phpunit.xml
. 1 / 1 (100%)
Time: 00:00.024, Memory: 16.00 MB
OK (1 test, 1 assertion)
SonarQube environment:
08:54:26.584 INFO SonarScanner CLI 8.0.1.6346
08:54:26.591 INFO Linux 6.18.39-talos amd64
08:54:28.089 INFO Communicating with SonarQube Server 2026.4.1.126914
08:54:28.091 INFO JRE provisioning: os[linux], arch[x86_64]
08:54:32.557 INFO Starting SonarScanner Engine…
08:54:32.557 INFO Java 21.0.11 Eclipse Adoptium (64-bit)