MantisBT

View Issue Details Jump to Notes ] Issue History ] Print ]
IDProjectCategoryView StatusDate SubmittedLast Update
0001541XdebugCode Coveragepublic2018-03-26 15:422018-03-26 15:48
Reportertheoboldt 
Assigned To 
PrioritynormalSeveritymajorReproducibilityalways
StatusnewResolutionopen 
PlatformLinuxOSUbuntuOS Version16.04.1
Product Version2.6.0 
Target VersionFixed in Version 
Summary0001541: switch/case case is not covered when using php-fpm php 7.0
DescriptionWhen 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}
<?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);
?>

{code}

When executing above code via CLI, following output is generated:
{code}
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
        )

)

{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}
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
        )
)

{code}
Steps To ReproduceExecute provided using php 7.0.28 snipped via php-fpm and via cli as well, compare results
TagsPHP7
Operating System
PHP Version7.0.25-7.0.29
Attached Files? file icon switch_case.php [^] (827 bytes) 2018-03-26 15:42

- Relationships

-  Notes
There are no notes attached to this issue.

- Issue History
Date Modified Username Field Change
2018-03-26 15:42 theoboldt New Issue
2018-03-26 15:42 theoboldt File Added: switch_case.php
2018-03-26 15:48 theoboldt Tag Attached: PHP7


Copyright © 2000 - 2018 MantisBT Team
Powered by Mantis Bugtracker