View Issue Details
ID | Project | Category | View Status | Date Submitted | Last Update |
---|---|---|---|---|---|
0001798 | Xdebug | Code Coverage | public | 2020-06-14 17:28 | 2021-04-08 09:50 |
Reporter | dvdoug | Assigned To | derick | ||
Priority | normal | Severity | minor | Reproducibility | always |
Status | resolved | Resolution | won't fix | ||
Product Version | 2.9.6 | ||||
Target Version | 3.0dev | ||||
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 interface MyInterface } MyClass.php Test script A (file included during first call, second call gives different line numbers) xdebug_start_code_coverage(XDEBUG_CC_UNUSED | XDEBUG_CC_DEAD_CODE); Test script B (file included before coverage begins) xdebug_start_code_coverage(XDEBUG_CC_UNUSED | XDEBUG_CC_DEAD_CODE); | ||||
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" |
|
I have had a long look at this, and I think I have come to the conclusion that I do not want to address this right now. Code coverage analyses which code can be executed when code coverage is active, and a new scope (script, method, or function) is seen for the first time. When code then runs, it modifies this information with whether code has been executed when specific lines have been hit. When code coverage was implemented, it was never meant to be stopped and started between every test, but rather, collect information for the whole execution as all the tests in one go. This means that it is now impossible to reset the internal collected information to the analysed stated (which line is executable etc). The only way would be to reanalyse everything. And that'd be so slow that nobody would ever want to do code coverage again. The only way to solve this is to split the "analyse what code can do what" and "collect which lines/etc have been hit" into two separate internal data stores, and merge that information when returning it with xdebug_get_code_coverage(). That's going to be a major undertaking (read: months), and I don't think I will have the time for that, considering all the other issues I want to fix, and features to add. |
Date Modified | Username | Field | Change |
---|---|---|---|
2020-06-14 17:28 | dvdoug | New Issue | |
2020-06-20 15:07 | derick | Status | new => acknowledged |
2020-07-03 17:06 | dvdoug | Note Added: 0005424 | |
2021-03-17 08:51 | derick | Target Version | => 3.0dev |
2021-04-08 09:50 | derick | Assigned To | => derick |
2021-04-08 09:50 | derick | Status | acknowledged => resolved |
2021-04-08 09:50 | derick | Resolution | open => won't fix |
2021-04-08 09:50 | derick | Note Added: 0005821 |