View Issue Details

IDProjectCategoryView StatusLast Update
0001798XdebugCode Coveragepublic2020-07-03 17:06
ReporterdvdougAssigned To 
PrioritynormalSeverityminorReproducibilityalways
Status acknowledgedResolutionopen 
Product Version2.9.6 
Target VersionFixed in Version 
Summary0001798: Inconsistent reporting of executable lines
DescriptionWhen 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 ReproduceMyInterface.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());
TagsNo tags attached.
Operating System
PHP Version7.4.0-7.4.4

Activities

dvdoug

2020-07-03 17:06

reporter   ~0005424

https://github.com/sebastianbergmann/php-code-coverage/issues/774 suggests this might apply to "extends" as well as "implements"

Issue History

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