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.76k stars 370 forks source link

Calculation of Branch Coverage Totals is wrong - or at least misleading - when untested code exists #1007

Open theseer opened 11 months ago

theseer commented 11 months ago
Q A
php-code-coverage version 10.1.3
PHP version 8.2.9
Driver Xdebug
Xdebug version (if used) 3.2.2
Installation Method PHPUnit PHAR
Usage Method PHPUnit
PHPUnit version (if used) 10.3.1

image

The above 100% - 5/5 total for serializer is wrong, as the next screenshot shows:

image

The 100% - 5/5 total is only correct for the tested/covered files of this folder. Given there are untested/uncovered files present, that total should be less than 100%, and whatever the amount of branches might be ;)

I do realize we probably do not have that information (hence the n/a). But then we probably shouldn't calculate the total?

sebastianbergmann commented 11 months ago

@dvdoug Do you have any insight on this? Thanks!

dvdoug commented 11 months ago

I do realize we probably do not have that information (hence the n/a)

Yes, it's exactly that - the branches/paths are calculated by Xdebug, so if a file isn't processed then it's unknown (N.B. processed does not mean tested, merely loaded is sufficient). For the purposes of the statistical calculations, unknown is treated as 0 (see https://github.com/sebastianbergmann/php-code-coverage/blob/main/src/Node/File.php#L393 etc)

For v9, anyone who had processUncoveredFiles set to true wouldn't encounter this, as all files would be include()d but that setting doesn't exist anymore.

But then we probably shouldn't calculate the total?

I wouldn't recommend that, because that would mean that the root-level stats would display n/a if there was even a single uncovered file in the entire report - but maybe the number could be displayed with an asterisk and a tooltip that explains it's based on partial data?

sebastianbergmann commented 11 months ago

@dvdoug Thank you for your insight!