Skip to content

Code Coverage targets are handled in case-sensitive manner #1064

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
DeveloperRob opened this issue Mar 14, 2025 · 0 comments
Closed

Code Coverage targets are handled in case-sensitive manner #1064

DeveloperRob opened this issue Mar 14, 2025 · 0 comments
Assignees
Labels

Comments

@DeveloperRob
Copy link

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.

@sebastianbergmann sebastianbergmann transferred this issue from sebastianbergmann/phpunit Mar 15, 2025
@sebastianbergmann 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
@sebastianbergmann sebastianbergmann self-assigned this Mar 15, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

2 participants