View Issue Details

IDProjectCategoryView StatusLast Update
0001938XdebugCode Coveragepublic2021-03-17 08:29
Reporterjonnybarnes Assigned Toderick  
PrioritynormalSeverityminorReproducibilityalways
Status acknowledgedResolutionopen 
PlatformAppleOSmacOSOS Version11.1
Product Version3.0.2 
Target Version3.1dev 
Summary0001938: Branches in traist aren’t marked as executed
DescriptionI initially thought this was an error in PHPUnit and reported there. They said it was a bug in XDebug itself.

This is definitely happening in PHP8 with XDebug 3, it may be happening on older versions as well?

If I have a method in a trait, and use that method in a class, and look for code coverage based on branches, I can not get 100% coverage.

Here’s a smallest reproducible example: https://github.com/jonnybarnes/trait-path-coverage

The paths and branches for the trait are marked as zero coverage:
```
App\FooTrait
  Methods: 100.00% ( 1/ 1) Paths: 0.00% ( 0/ 1) Branches: 0.00% ( 0/ 1) Lines: 100.00% ( 1/ 1)
```
Steps To ReproduceImport a trait into a class and use its methods. Then measure the path or branch coverage of the codebase. the trait will have 0% path and branch coverage.
Additional InformationOne of the contributors over at PHPUnit thinks it’s a bug in XDebug, they provided this additional information on my bug report from their testing on my minimal case repo:

```
C:\tmp\trait-path-coverage\src\Bar.php = {array} [2]
 lines = {array} [4]
  7 = {int} 1
  13 = {int} 1
  14 = {int} -2
  16 = {int} 1
 functions = {array} [2]
  App\Bar->useTrait = {array} [2]
   branches = {array} [1]
    0 = {array} [7]
     op_start = {int} 0
     op_end = {int} 8
     line_start = {int} 11
     line_end = {int} 14
     hit = {int} 1
     out = {array} [0]
     out_hit = {array} [0]
   paths = {array} [1]
  {main} = {array} [2]
   branches = {array} [1]
    0 = {array} [7]
     op_start = {int} 0
     op_end = {int} 3
     line_start = {int} 3
     line_end = {int} 16
     hit = {int} 1
     out = {array} [1]
     out_hit = {array} [1]
   paths = {array} [1]
C:\tmp\trait-path-coverage\src\FooTrait.php = {array} [2]
 lines = {array} [3]
  11 = {int} 1 <------------------------------------------- this says the line was executed
  12 = {int} -2
  14 = {int} 1
 functions = {array} [2]
  App\FooTrait->returnsTrue = {array} [2]
   branches = {array} [1]
    0 = {array} [7]
     op_start = {int} 0
     op_end = {int} 5
     line_start = {int} 9
     line_end = {int} 12
     hit = {int} 0 <----------------------------------------- this says the branch was not
     out = {array} [0]
     out_hit = {array} [0]
   paths = {array} [1]
  {main} = {array} [2]
   branches = {array} [1]
    0 = {array} [7]
     op_start = {int} 0
     op_end = {int} 2
     line_start = {int} 3
     line_end = {int} 14
     hit = {int} 1
     out = {array} [1]
     out_hit = {array} [1]
   paths = {array} [1]
```
TagsNo tags attached.
Operating System
PHP Version8.0.0-8.0.4

Activities

derick

2021-02-18 11:21

administrator   ~0005669

I'll have a look in the next week or so.

Issue History

Date Modified Username Field Change
2021-01-23 16:01 jonnybarnes New Issue
2021-02-18 11:21 derick Assigned To => derick
2021-02-18 11:21 derick Status new => acknowledged
2021-02-18 11:21 derick Note Added: 0005669
2021-03-17 08:29 derick Target Version => 3.1dev