Skip to content

CodeCoverage depends on autoload order #889

Description

@Slamdunk
Q A
php-code-coverage version 9.2.10
PHP version 8.1.2
Driver Tested on both PCOV & Xdebug
Xdebug version 3.1.2
Installation Method Composer
Usage Method PHPUnit
PHPUnit version 9.5.13

Hi, currently CodeCoverage depends on code execution order.
I created a self contained repo that shows this behavior in https://github.com/Slamdunk/phpunit_codecoverage_bug#readme

Basically, given the following code:

/* 1 */ class A
/* 2 */ {
/* 3 */     public function inArray(): bool
/* 4 */     {
/* 5 */         return \in_array(1, [
/* 6 */             AType::OPT,
/* 7 */         ], true);
/* 8 */     }
/* 9 */ }
  1. lines 6 and 7 are not considered LOC if AType was already loaded and parsed before the A is used in the test
  2. otherwise if AType is unknown to PHP during inArray call, lines 6 and 7 are considered LOC.

This messes CodeCoverage merging in context like ParaTest where test execution is isolated but not deterministic.

Merging two CC reports coming from different tests run in different processes can result in something like this:

image

Which doesn't make much sense

I don't know if this library can do much about this, maybe @krakjoe and @derickr could help

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions