View Issue Details

IDProjectCategoryView StatusLast Update
0001069XdebugUncategorizedpublic2014-08-14 11:01
Reportertarlabs Assigned Toderick  
PrioritynormalSeveritymajorReproducibilityalways
Status resolvedResolutionnot fixable 
PlatformWindowsOSWin7OS Versionx64
Product Version2.2.5 
Summary0001069: Wrong coverage generated for single line if statements
Description

I am using https://github.com/sebastianbergmann/php-code-coverage to generate code coverage report. This PHP code in background uses xDebug. I am going to open same bug on their issue list also, but I believe this is a xDebug bug only.

Steps To Reproduce

To reproduce do the following:

create a info.php page:

<?php
function doWork($x){
if($x != 1)
echo "Passed";
else
echo "Failed";
}

doWork($_REQUEST['abc']);

?>

Now call this page twice using below URLS

http://localhost/info.php?abc=1
http://localhost/info.php?abc=2

I have used below prepend file in my apache settings:
<?php
require_once 'c:/coverage/vendor/autoload.php';

$coverage = new PHP_CodeCoverage;
$filter = $coverage->filter();

$filter->addFileToBlacklist('c:/echo.php');
$filter->addFileToBlacklist('c:/echo2.php');
$filter->addDirectoryToBlacklist("c:/coverage/");

$coverage->start("test # " . rand(20, 200));

?>

and below append file

<?php
$coverage->stop();

$writer = new PHP_CodeCoverage_Report_Clover();
$writer->process($coverage,'c:/coverage/report/clover.xml');
$writer = new PHP_CodeCoverage_Report_HTML;
$writer->process($coverage, 'c:/coverage/report/');

?>

The issue is that, if I have used a single line if, then i get code coverage xml as below

<?xml version="1.0" encoding="UTF-8"?>
<coverage generated="1407999027">
<project timestamp="1407999027">
<file name="C:\source codes\work\IPCM\branches\marinetime\ui/info.php">
<line num="3" type="stmt" count="1"/>
<line num="4" type="stmt" count="1"/>
<line num="6" type="stmt" count="0"/>
<line num="7" type="stmt" count="1"/>
<line num="9" type="stmt" count="1"/>
<metrics loc="9" ncloc="9" classes="0" methods="0" coveredmethods="0" conditionals="0" coveredconditionals="0" statements="5" coveredstatements="4" elements="5" coveredelements="4"/>
</file>
<metrics files="1" loc="9" ncloc="9" classes="0" methods="0" coveredmethods="0" conditionals="0" coveredconditionals="0" statements="5" coveredstatements="4" elements="5" coveredelements="4"/>
</project>
</coverage>

For both URLs, which is anyways wrong as Once I get inside If and then inside else. But if I modify the code as below

<?php
function doWork($x){
if($x != 1)
{
echo "Passed";
}
else
{
echo "Failed";
}
}

doWork($_REQUEST['abc']);

?>

Then the coverage report comes fine

<?xml version="1.0" encoding="UTF-8"?>
<coverage generated="1407999163">
<project timestamp="1407999163">
<file name="C:\source codes\work\IPCM\branches\marinetime\ui/info.php">
<line num="3" type="stmt" count="1"/>
<line num="4" type="stmt" count="1"/>
<line num="5" type="stmt" count="0"/>
<line num="6" type="stmt" count="0"/>
<line num="9" type="stmt" count="1"/>
<line num="11" type="stmt" count="1"/>
<line num="13" type="stmt" count="1"/>
<metrics loc="13" ncloc="13" classes="0" methods="0" coveredmethods="0" conditionals="0" coveredconditionals="0" statements="7" coveredstatements="5" elements="7" coveredelements="5"/>
</file>
<metrics files="1" loc="13" ncloc="13" classes="0" methods="0" coveredmethods="0" conditionals="0" coveredconditionals="0" statements="7" coveredstatements="5" elements="7" coveredelements="5"/>
</project>
</coverage>

Let me know if you need any further information

Additional Information

PHP version

PHP 5.5.12 (cli) (built: Apr 30 2014 11:20:55)
Copyright (c) 1997-2014 The PHP Group
Zend Engine v2.5.0, Copyright (c) 1998-2014 Zend Technologies
with Xdebug v2.2.5, Copyright (c) 2002-2014, by Derick Rethans

TagsNo tags attached.
Operating System
PHP Version5.5.5-5.5.9

Relationships

duplicate of 0000842 resolvedderick Can't debug conditional statements without a block 

Activities

derick

2014-08-14 11:01

administrator   ~0002876

This is not something I can fix. PHP does in those cases not generate the correct line numbers for opcodes. It is similar to 0000842 (which has a good explanation) and 0000895.

Issue History

Date Modified Username Field Change
2014-08-14 06:55 tarlabs New Issue
2014-08-14 11:01 derick Note Added: 0002876
2014-08-14 11:01 derick Relationship added duplicate of 0000842
2014-08-14 11:01 derick Status new => resolved
2014-08-14 11:01 derick Resolution open => not fixable
2014-08-14 11:01 derick Assigned To => derick
2016-07-31 12:36 derick Category Usage problems => Usage problems (Crashes)
2016-07-31 12:38 derick Category Usage problems (Crashes) => Usage problems (Wrong Results)
2020-03-12 16:35 derick Category Usage problems (Wrong Results) => Variable Display
2020-03-12 16:38 derick Category Variable Display => Uncategorized