You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
When running PHPUnit and generating code coverage reports, CoversClass / CoversMethod attributes need to be provided with the class name in a case sensitive fashion, despite PHP itself treating classes in a case insensitive fashion.
Current behavior
In the 'how to reproduce' example, HelloWorldTest.php works as expected, while HelloWorldTest2.php lists the warning:
1) HelloWorld2Test::testReturnsExpectedString
Class Helloworld is not a valid target for code coverage
How to reproduce
HelloWorld.php:
<?php
class HelloWorld{
public static function helloWorld(){
return "Hello World";
}
}
HelloWorldTest.php:
<?php
use PHPUnit\Framework\TestCase;
use PHPUnit\Framework\Attributes\CoversClass;
#[CoversClass(\HelloWorld::class)]
class HelloWorldTest extends TestCase{
public function testReturnsExpectedString(): void {
$this->assertEquals("Hello World", HelloWorld::helloWorld());
}
}
HelloWorld2Test.php:
<?php
use PHPUnit\Framework\TestCase;
use PHPUnit\Framework\Attributes\CoversClass;
#[CoversClass(\Helloworld::class)]
class HelloWorld2Test extends TestCase{
public function testReturnsExpectedString(): void {
$this->assertEquals("Hello World", HelloWorld::helloWorld());
}
}
Expected behavior
No warnings ideally. If however it would cause performance or implementation issues to match code coverage targets in a case insensitive fashion, a more specific warning (e.g. Class Helloworld is not a valid target for code coverage, did you mean class HelloWorld) would be very helpful, as the cause of the warning can be hard to spot.
The text was updated successfully, but these errors were encountered:
sebastianbergmann
changed the title
Code coverage targets must match in a case sensitive fashion
Code Coverage targets are handled in case-sensitive manner
Mar 15, 2025
Summary
When running PHPUnit and generating code coverage reports,
CoversClass
/CoversMethod
attributes need to be provided with the class name in a case sensitive fashion, despite PHP itself treating classes in a case insensitive fashion.Current behavior
In the 'how to reproduce' example,
HelloWorldTest.php
works as expected, whileHelloWorldTest2.php
lists the warning:How to reproduce
HelloWorld.php
:HelloWorldTest.php
:HelloWorld2Test.php
:Expected behavior
No warnings ideally. If however it would cause performance or implementation issues to match code coverage targets in a case insensitive fashion, a more specific warning (e.g.
Class Helloworld is not a valid target for code coverage, did you mean class HelloWorld
) would be very helpful, as the cause of the warning can be hard to spot.The text was updated successfully, but these errors were encountered: