View Issue Details

IDProjectCategoryView StatusLast Update
0001938XdebugCode Coveragepublic2021-10-04 20:42
Reporterjonnybarnes Assigned Toderick  
PrioritynormalSeverityminorReproducibilityalways
Status closedResolutionfixed 
PlatformAppleOSmacOSOS Version11.1
Product Version3.0.2 
Target Version3.1devFixed in Version3.1.0 
Summary0001938: Branches in traits aren’t marked as executed
Description

I 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 Reproduce

Import 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 Information

One 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.

derick

2021-08-30 23:19

administrator   ~0005997

https://github.com/xdebug/xdebug/pull/776

dvdoug

2021-09-13 15:58

reporter   ~0006004

I've tested this with 3.1.0beta1 and am wondering if the name-munging is an essential part of the fix or was just a nice-to-have whilst debugging? (i.e. the returnsTrue method in the trait being recorded in the output as returnsTrue{trait-method:bug01938-FooTrait.inc:9-12}

php-code-coverage currently has an assumption that they will always be the same.

derick

2021-10-04 09:32

administrator   ~0006072

There is a need for that, because it shows the actual trait method, not the imported version. The same method can be imported by multiple classes, but is actually the same method. I do need to remember this, I think.

dvdoug

2021-10-04 19:11

reporter   ~0006075

Is there any possibility of restoring the actual trait name to the array key alongside the annotation? It's no longer present with 3.1

Before:
App\FooTrait->returnsTrue => [...]

Currently:
returnsTrue{trait-method:/src/FooTrait.php:9-16} => [...]

It would be really helpful if it could be:
App\FooTrait->returnsTrue{trait-method:/src/FooTrait.php:9-16} => [...]

I'm working on a patch for php-code-coverage to understand the new data, and stripping off the annotation is fairly trivial but I'd prefer not to have to try and reconstruct the FQCN\Traitname in userland

derick

2021-10-04 20:42

administrator   ~0006076

Can you make a new issue for that?

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
2021-08-30 18:33 derick Summary Branches in traist aren’t marked as executed => Branches in traits aren’t marked as executed
2021-08-30 23:19 derick Note Added: 0005997
2021-08-31 16:23 derick Status acknowledged => closed
2021-08-31 16:23 derick Resolution open => fixed
2021-08-31 16:23 derick Fixed in Version => 3.1dev
2021-09-05 16:15 derick Fixed in Version 3.1dev => 3.1.0beta1
2021-09-13 15:58 dvdoug Note Added: 0006004
2021-10-04 09:32 derick Note Added: 0006072
2021-10-04 09:32 derick Fixed in Version 3.1.0beta1 => 3.1.0
2021-10-04 19:11 dvdoug Note Added: 0006075
2021-10-04 20:42 derick Note Added: 0006076