Closed
Description
Q | A |
---|---|
PHPUnit version | 12.0.7 |
PHP version | 8.3.19 with Xdebug 3.3.2 |
Installation Method | Composer |
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, 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.