sebastianbergmann / php-code-coverage

Library that provides collection, processing, and rendering functionality for PHP code coverage information.
BSD 3-Clause "New" or "Revised" License
8.81k stars 373 forks source link

Coverage for class/interface/trait itself is not measured #1031

Closed mvorisek closed 8 months ago

mvorisek commented 8 months ago
Q A
php-code-coverage version 10.1.11
PHP version 8.3.0
Driver Xdebug
PCOV version (if used) n/a
Xdebug version (if used) 3.3.1
Installation Method Composer
Usage Method PHPUnit
PHPUnit version (if used) 10.5.9

repro code:

<?php

class X
{
}

generates zero coverage lines (which makes the file completely ignored for CodeCov).

I would expect coverage to be emit on the l3 (l9 in the screenshot below) (ie. the line where the class starts). The meaning is if the class has been included or not.

image

mvorisek commented 8 months ago

@Slamdunk can you please have a look

sebastianbergmann commented 8 months ago

This is by design: a class declaration is not considered executable.

mvorisek commented 8 months ago

@sebastianbergmann may I know why? Here is a usecase: https://github.com/atk4/ui/blob/5.0.0/src/Exception/ExitApplicationError.php - without this issue, we cannot tell if the class is used/covered or not.

sebastianbergmann commented 8 months ago

Declarations are not relevant at runtime.