View Issue Details
ID | Project | Category | View Status | Date Submitted | Last Update |
---|---|---|---|---|---|
0001798 | Xdebug | Code Coverage | public | 2020-06-14 17:28 | 2020-07-03 17:06 |
Reporter | dvdoug | Assigned To | |||
Priority | normal | Severity | minor | Reproducibility | always |
Status | acknowledged | Resolution | open | ||
Product Version | 2.9.6 | ||||
Summary | 0001798: Inconsistent reporting of executable lines | ||||
Description | When a class implements an interface and the class is first included while code coverage is active, then the class definition line is counted as executable when coverage is retrieved the first time. But only the first time. When the same file is included while code coverage is *not* active, then the class definition line is never counted as executable. This results in inconsistent code coverage numbers depending on external factors e.g. whether PHPUnit's processUncoveredFiles mode is on or off, or whether Symfony has decided to recompile it's container before a particular run. This does not seem to affect simple classes that do not implement an interface, there the class definition always seems to be considered non-executable. I would suggest this case is handled the same. | ||||
Steps To Reproduce | MyInterface.php <?php interface MyInterface { } MyClass.php <?php require_once 'MyInterface.php'; class MyClass implements MyInterface { public function foo() { $foo = 'bar'; } } Test script A (file included during first call, second call gives different line numbers) <?php xdebug_start_code_coverage(XDEBUG_CC_UNUSED | XDEBUG_CC_DEAD_CODE); require_once 'MyClass.php'; print_r(xdebug_get_code_coverage()); xdebug_stop_code_coverage(); xdebug_start_code_coverage(XDEBUG_CC_UNUSED | XDEBUG_CC_DEAD_CODE); $class = new MyClass(); $class->foo(); print_r(xdebug_get_code_coverage()); Test script B (file included before coverage begins) <?php require_once 'MyClass.php'; xdebug_start_code_coverage(XDEBUG_CC_UNUSED | XDEBUG_CC_DEAD_CODE); $class = new MyClass(); $class->foo(); print_r(xdebug_get_code_coverage()); | ||||
Tags | No tags attached. | ||||
Operating System | |||||
PHP Version | 7.4.0-7.4.4 | ||||
|
https://github.com/sebastianbergmann/php-code-coverage/issues/774 suggests this might apply to "extends" as well as "implements" |