View Issue Details

IDProjectCategoryView StatusLast Update
0000440XdebugCode Coveragepublic2020-03-12 17:35
Reporterdanielpr Assigned Toderick  
PrioritynormalSeverityfeatureReproducibilityalways
Status resolvedResolutionno change required 
Summary0000440: Difference in code-coverage of class-declaration
Description

We've experienced a bug in PHPUnit, which sometimes marks a class-declaration as executable code and says, reports this code as not covered:
http://www.phpunit.de/ticket/740

So i narrowed it down to the behaviour of XDebug. The executable lines output shows a difference depending if a file is loaded before or after the xdebug_start_code_coverage.

Additional Information

Class1.php:
<?php
class Class1
{
public function __construct()
{
$i = 1;
}

    public function foo()
    {
        $bar = 1;
    }

}
?>

Class2.php (same as Class1 except the class-declaration :) ):
<?php
class Class2
{
public function __construct()
{
$i = 1;
}

    public function foo()
    {
        $bar = 1;
    }

}
?>

Test Script:
<?php
require 'Class1.php';
xdebug_start_code_coverage(XDEBUG_CC_UNUSED | XDEBUG_CC_DEAD_CODE);
$c = new Class1;

require 'Class2.php';
$c = new Class2;

print_r(xdebug_get_code_coverage());
?>

RESULT:
Array
(
[Class1.php] => Array
(
[6] => 1
[7] => 1
[11] => -1
[12] => -1
)
[Class2.php] => Array
(
[3] => 1 (class definition)
[6] => 1
[7] => 1
[11] => -1
[12] => -1
[14] => 1 (class closing bracket)
)
)

TagsNo tags attached.
Operating System
PHP Version5.2.8

Activities

derick

2009-10-17 17:54

administrator   ~0001102

This is not a bug. Xdebug can only scans items (files, functions, methods) when they are loaded and code coverage is enabled. The class file is loaded before code coverage is enabled, and is therefore not picked up in the coverage report. The methods are scanned when they are run as well, so it works there.

Issue History

Date Modified Username Field Change
2009-05-11 21:31 danielpr New Issue
2009-05-11 21:31 danielpr PHP Version => 5.2.8
2009-05-11 21:31 danielpr Xdebug Version => 2.0.4-dev
2009-10-17 17:54 derick Note Added: 0001102
2009-10-17 17:54 derick Status new => resolved
2009-10-17 17:54 derick Resolution open => no change required
2009-10-17 17:54 derick Assigned To => derick
2020-03-12 16:55 derick Severity major => feature
2020-03-12 17:35 derick Category Feature/Change request => Code Coverage