Skip to content

Incorrect code coverage metadata does not prevent code coverage data from being collected #5351

@jrfnl

Description

@jrfnl
Q A
php-code-coverage version 10.1.1
PHP version 8.2.5
Driver Xdebug
Xdebug version (if used) 3.2.1
Installation Method irrelevant, same result in both cases
Usage Method PHPUnit
PHPUnit version (if used) 10.1.2

Given

  • A phpunit.xml.dist config file which includes the forceCoversAnnotation="true" (PHPUnit 9.x) or requireCoverageMetadata="true" (PHPUnit 10.x) directive;
  • And a test which has a @covers tag for a method which doesn't exist.

I'd expect

That no code coverage would be recorded for the test with the incorrect @covers tag, along the same lines as if the test had a @covers tag for a method which wasn't run during the test.

And if the test had multiple @covers tags, I'd expect code coverage only to be recorded for the valid tags.

What happened instead

Coverage was recorded as if forceCoversAnnotation/requireCoverageMetadata was set to false, i.e. all code which was run during the test now shows as covered, even though there are no tests with the appropriate @covers tags for that code.

Reproduction scenario

See the individual commits in the https://github.com/jrfnl/bug-report-reproduction-scenarios/tree/php-code-coverage/997-wrong-covers-tag-wrong-coverage branch.
Each commit includes the coverage reports (text summary in the commit message, HTML + Clover reports in the actual commits).

Metadata

Metadata

Labels

event/code-sprint/2024-03PHPUnit Code Sprint: March 2024feature/code-coverageIssues related to code coverage (but not php-code-coverage)feature/metadataIssues related to attributes and annotationstype/bugSomething is broken

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions