View Issue Details

IDProjectCategoryView StatusLast Update
0001541XdebugCode Coveragepublic2019-08-26 12:37
Reportertheoboldt Assigned Toderick  
PrioritynormalSeveritymajorReproducibilityalways
Status closedResolutionduplicate 
PlatformLinuxOSUbuntuOS Version16.04.1
Product Version2.6.0 
Target Version2.8.0devFixed in Version2.8.0beta2 
Summary0001541: switch/case case is not covered when using php-fpm php 7.0
Description

When executing switch/case within a function, no case line of executed cases is marked as covered, except the following:

  • The first line is marked as covered as expected
  • The "default" case is marked as covered as expected

The lines are marked as covered as expected when the same file is executed via CLI using same php/xdebug version.

{code}
<pre>
<?php

function a($option) {
switch ($option) {
case 'first':
$option .= '_covered';
break;
case 'second':
$option .= '_covered';
break;
case 'third':
$option .= '_covered';
break;
default:
$option .= '_covered';
break;
}
return $option;
}

xdebug_start_code_coverage(XDEBUG_CC_UNUSED | XDEBUG_CC_DEAD_CODE);

a('first');
a('second');
a('third');
a('default');

$coverage = xdebug_get_code_coverage();
xdebug_stop_code_coverage();

//EVALUATE (not part of proof)
print_r(
[
'phpversion(\'xdebug\')' => phpversion('xdebug'),
'phpversion()' => phpversion(),
'php_sapi_name()' => php_sapi_name()
]
);
print_r($coverage);
?>
</pre>
{code}

When executing above code via CLI, following output is generated:
{code}
<pre>
Array
(
[phpversion('xdebug')] => 2.6.0
[phpversion()] => 7.0.28-0ubuntu0.16.04.1
[php_sapi_name()] => cli
)
Array
(
[/intproj/users/erik/xdebug_coverage_issues/switch_case.php] => Array
(
[5] => 1
[6] => 1
[7] => 1
[8] => 1
[9] => 1
[10] => 1
[11] => 1
[12] => 1
[13] => 1
[15] => 1
[16] => 1
[18] => 1
[23] => 1
[24] => 1
[25] => 1
[26] => 1
[28] => 1
)

)
</pre>
{code}

When executing above code via Apache 2 (Server API: FPM/FastCGI, PHP API: 20151012, PHP Extension: 20151012) the output differs significantly for line 8 and 11:
{code}
<pre>
Array
(
[phpversion('xdebug')] => 2.6.0
[phpversion()] => 7.0.28-0ubuntu0.16.04.1
[php_sapi_name()] => fpm-fcgi
)
Array
(
[/intproj/users/erik/xdebug_coverage_issues/switch_case.php] => Array
(
[5] => 1
[6] => 1
[7] => 1
[8] => -1
[9] => 1
[10] => 1
[11] => -1
[12] => 1
[13] => 1
[15] => 1
[16] => 1
[18] => 1
[23] => 1
[24] => 1
[25] => 1
[26] => 1
[28] => 1
)
)
</pre>
{code}

Steps To Reproduce

Execute provided using php 7.0.28 snipped via php-fpm and via cli as well, compare results

TagsPHP7, php7.2
Attached Files
switch_case.php (827 bytes)   
<?php

function a($option) {
    switch ($option) {
        case 'first':
            $option .= '_covered';
            break;
        case 'second':
            $option .= '_covered';
            break;
        case 'third':
            $option .= '_covered';
            break;
        default:
            $option .= '_covered';
            break;
    }
    return $option;
}

xdebug_start_code_coverage(XDEBUG_CC_UNUSED | XDEBUG_CC_DEAD_CODE);

a('first');
a('second');
a('third');
a('default');

$coverage = xdebug_get_code_coverage();
xdebug_stop_code_coverage();


//EVALUATE (not part of proof)
echo "<pre>\n";
print_r(
    [
        'phpversion(\'xdebug\')' => phpversion('xdebug'),
        'phpversion()'           => phpversion(),
        'php_sapi_name()'        => php_sapi_name()
    ]
);
print_r($coverage);

?>
switch_case.php (827 bytes)   
Operating System
PHP Version7.0.25-7.0.29

Relationships

duplicate of 0001540 closedderick Multiline class instantiate within method call is not covered when using php-fpm 

Activities

theoboldt

2018-11-15 10:54

reporter   ~0004724

Still reproducible using xdebug 2.6.1.

derick

2018-12-06 12:11

administrator   ~0004749

Do you have opcache installed and enabled for the PHP-FPM install?

theoboldt

2018-12-06 15:21

reporter   ~0004750

Do you have opcache installed and enabled for the PHP-FPM install?
In the provided examples, opcache was installed and enabled. I performed some tests now using PHP 7.0.32-0ubuntu0.16.04.1. It's worth to notice that the results slightly differ when having opcache enabled/disabled, but issue in general still exists:

Result having opcache enabled:
{code}
Array
(
[phpversion('xdebug')] => 2.6.0
[phpversion()] => 7.0.32-0ubuntu0.16.04.1
[php_sapi_name()] => fpm-fcgi
)
Array
(
[/intproj/users/erik/switch_case.php] => Array
(
[5] => 1
[6] => 1
[7] => 1
[8] => -1
[9] => 1
[10] => 1
[11] => -1
[12] => 1
[13] => 1
[15] => 1
[16] => 1
[18] => 1
[23] => 1
[24] => 1
[25] => 1
[26] => 1
[28] => 1
)
)
{code}

Result having opcache disabled:
{code}
Array
(
[phpversion('xdebug')] => 2.6.0
[phpversion()] => 7.0.32-0ubuntu0.16.04.1
[php_sapi_name()] => fpm-fcgi
)
Array
(
[/intproj/users/erik/switch_case.php] => Array
(
[5] => 1
[6] => 1
[7] => 1
[8] => -1
[9] => 1
[10] => 1
[11] => -1
[12] => 1
[13] => 1
[15] => 1
[16] => 1
[18] => 1
[19] => -2
[23] => 1
[24] => 1
[25] => 1
[26] => 1
[28] => 1
)
)
{code}

theoboldt

2018-12-06 15:33

reporter   ~0004753

Also reproducible using php 7.2:

opcache enabled:
{code}
Array
(
[phpversion('xdebug')] => 2.6.0
[phpversion()] => 7.2.10-0ubuntu0.18.04.1
[php_sapi_name()] => fpm-fcgi
)
Array
(
[/intproj/users/erik/switch_case.php] => Array
(
[4] => 1
[5] => -1
[6] => 1
[7] => 1
[8] => -1
[9] => 1
[10] => 1
[11] => -1
[12] => 1
[13] => 1
[15] => 1
[16] => 1
[18] => 1
[23] => 1
[24] => 1
[25] => 1
[26] => 1
[28] => 1
)
)
{code}

opcache disabled:
{code}
Array
(
[phpversion('xdebug')] => 2.6.0
[phpversion()] => 7.2.10-0ubuntu0.18.04.1
[php_sapi_name()] => fpm-fcgi
)
Array
(
[/intproj/users/erik/switch_case.php] => Array
(
[4] => 1
[5] => -1
[6] => 1
[7] => 1
[8] => -1
[9] => 1
[10] => 1
[11] => -1
[12] => 1
[13] => 1
[15] => 1
[16] => 1
[18] => 1
[19] => -2
[23] => 1
[24] => 1
[25] => 1
[26] => 1
[28] => 1
)
)
{code}

derick

2019-01-22 22:27

administrator   ~0004834

I will have a look at this after Xdebug 2.7.0 has been released. I haven't reproduced it yet, so will leave the issue in "acknowledged" for now.

derick

2019-07-15 16:36

administrator   ~0005061

I can't reproduce this - is this still causing you trouble?

theoboldt

2019-07-16 09:43

reporter   ~0005063

Still reproducible using Xdebug 2.7.2, PHP FPM, having opcache enabled:
<pre>
Array
(
[phpversion('xdebug')] => 2.7.2
[phpversion()] => 7.2.19-0ubuntu0.18.04.1
[php_sapi_name()] => fpm-fcgi
)
Array
(
[/var/www/localhost/xdebug.php] => Array
(
[5] => 1
[6] => -1
[7] => 1
[8] => 1
[9] => -1
[10] => 1
[11] => 1
[12] => -1
[13] => 1
[14] => 1
[16] => 1
[17] => 1
[19] => 1
[24] => 1
[25] => 1
[26] => 1
[27] => 1
[29] => 1
)

)
</pre>

Still reproducible using Xdebug 2.7.2, PHP FPM, having opcache disabled:
<pre>
Array
(
[phpversion('xdebug')] => 2.7.2
[phpversion()] => 7.2.19-0ubuntu0.18.04.1
[php_sapi_name()] => fpm-fcgi
)
Array
(
[/var/www/localhost/xdebug.php] => Array
(
[5] => 1
[6] => -1
[7] => 1
[8] => 1
[9] => -1
[10] => 1
[11] => 1
[12] => -1
[13] => 1
[14] => 1
[16] => 1
[17] => 1
[19] => 1
[20] => -2
[24] => 1
[25] => 1
[26] => 1
[27] => 1
[29] => 1
)

)
</pre>

derick

2019-07-19 11:29

administrator   ~0005071

Last edited: 2019-07-19 11:29

I just spend another two hours setting this up in a new and pristine VM with Ubuntu 18.04.2 LTS, which from what I can see is the exact same environment.

The result is:

<b>Opcache disabled</b>:
<pre>
Array
(
[phpversion('xdebug')] => 2.7.2
[phpversion()] => 7.2.19-0ubuntu0.18.04.1
[php_sapi_name()] => fpm-fcgi
)
Array
(
[/var/www/html/test.php] => Array
(
[5] => 1
[6] => 1
[7] => 1
[8] => 1
[9] => 1
[10] => 1
[11] => 1
[12] => 1
[13] => 1
[14] => 1
[16] => 1
[17] => 1
[19] => 1
[20] => -2
[24] => 1
[25] => 1
[26] => 1
[27] => 1
[29] => 1
)

)
</pre>

<b>Opcache enabled:</b>
<pre>
Array
(
[phpversion('xdebug')] => 2.7.2
[phpversion()] => 7.2.19-0ubuntu0.18.04.1
[php_sapi_name()] => fpm-fcgi
)
Array
(
[/var/www/html/test.php] => Array
(
[5] => 1
[6] => 1
[7] => 1
[8] => 1
[9] => 1
[10] => 1
[11] => 1
[12] => 1
[13] => 1
[14] => 1
[16] => 1
[17] => 1
[19] => 1
[24] => 1
[25] => 1
[26] => 1
[27] => 1
[29] => 1
)

)
</pre>

As you can see, I still can't reproduce this. I installed Xdebug from source and I also tried the php-xdebug package (Xdebug 2.6.0), and I still get the same result.

There must be something different in your environment, although I can't see what would impact this. Is there any chance you can set-up a VM or something that shows the problem and you can give me access to?

theoboldt

2019-07-19 14:04

reporter   ~0005079

We identified the configuration responsible for the error. If the configuration contains <pre>xdebug.coverage_enable = 0</pre>, the error occurs. If the related configuration option is put in comments, no error occurs. If <pre>xdebug.coverage_enable = 1</pre> is configured, no error occurs.

I'd say that this should still be regarded as error, since it prevents users from collecting code coverage data of only specific snippets.

We created a docker image which can be used to reproduce the error. When docker container is loaded and running, the container provides a web server at port 80. Proof can be found via <pre>/index.php</pre>.

The bzip2 compressed docker image can be accessed within 7 days via: https://send.firefox.com/download/9b4b0fd39342cbca/#s7XDxm7K7sSWRmHY113vlQ

derick

2019-07-19 14:25

administrator   ~0005080

Oh!

If you turn off xdebug.coverage_enable then Xdebug should not do any code coverage whatsoever, so that is a bug.

I can reproduce it when that configuration setting, so feel free to remove your Docker container.

derick

2019-07-27 22:39

administrator   ~0005095

Fixed in 2.8.0beta2, by making sure there is a warning when you want to use code coverage when xdebug.code_coverage=0 (and duplicate of 0001540)

Issue History

Date Modified Username Field Change
2018-03-26 14:42 theoboldt New Issue
2018-03-26 14:42 theoboldt File Added: switch_case.php
2018-03-26 14:48 theoboldt Tag Attached: PHP7
2018-11-15 10:54 theoboldt Note Added: 0004724
2018-12-06 12:11 derick Note Added: 0004749
2018-12-06 12:11 derick Assigned To => derick
2018-12-06 12:11 derick Status new => feedback
2018-12-06 15:21 theoboldt Note Added: 0004750
2018-12-06 15:21 theoboldt Status feedback => assigned
2018-12-06 15:33 theoboldt Note Added: 0004753
2019-01-22 22:27 derick Note Added: 0004834
2019-01-22 22:27 derick Status assigned => acknowledged
2019-01-22 22:27 derick Target Version => 2.7.0dev
2019-06-28 11:16 derick Target Version 2.7.0dev => 2.8.0dev
2019-07-15 16:36 derick Status acknowledged => feedback
2019-07-15 16:36 derick Note Added: 0005061
2019-07-16 09:43 theoboldt Note Added: 0005063
2019-07-16 09:43 theoboldt Status feedback => assigned
2019-07-16 09:45 theoboldt Tag Attached: php7.2
2019-07-19 11:29 derick Status assigned => feedback
2019-07-19 11:29 derick Note Added: 0005071
2019-07-19 11:29 derick Note Edited: 0005071
2019-07-19 14:04 theoboldt Note Added: 0005079
2019-07-19 14:04 theoboldt Status feedback => assigned
2019-07-19 14:25 derick Note Added: 0005080
2019-07-19 14:25 derick Status assigned => confirmed
2019-07-27 22:39 derick Status confirmed => resolved
2019-07-27 22:39 derick Resolution open => duplicate
2019-07-27 22:39 derick Fixed in Version => 2.8.0dev
2019-07-27 22:39 derick Note Added: 0005095
2019-07-27 22:39 derick Relationship added duplicate of 0001540
2019-08-26 12:37 derick Status resolved => closed
2019-08-26 12:37 derick Fixed in Version 2.8.0dev => 2.8.0beta2