View Issue Details

IDProjectCategoryView StatusLast Update
0002164XdebugCode Coveragepublic2023-09-04 11:06
Reportersebastian Assigned Toderick  
PrioritynormalSeveritymajorReproducibilityhave not tried
Status confirmedResolutionopen 
Product Version3.2.0 
Target Version3.3dev 
Summary0002164: Branch and Path Coverage wrong for first class callable
Description

Copied here from https://github.com/sebastianbergmann/php-code-coverage/issues/984#issuecomment-1454892521.

Array
(
    [Foo->bar] => Array
        (
            [branches] => Array
                (
                    [0] => Array
                        (
                            [op_start] => 0
                            [op_end] => 6
                            [line_start] => 7
                            [line_end] => 10
                            [hit] => 0
                            [out] => Array
                                (
                                )

                            [out_hit] => Array
                                (
                                )
                        )
                )

            [paths] => Array
                (
                    [0] => Array
                        (
                            [path] => Array
                                (
                                    [0] => 0
                                )

                            [hit] => 0
                        )
                )
        )

    [bar] => Array
        (
            [branches] => Array
                (
                    [0] => Array
                        (
                            [op_start] => 0
                            [op_end] => 6
                            [line_start] => 7
                            [line_end] => 10
                            [hit] => 1
                            [out] => Array
                                (
                                )

                            [out_hit] => Array
                                (
                                )
                        )
                )

            [paths] => Array
                (
                    [0] => Array
                        (
                            [path] => Array
                                (
                                    [0] => 0
                                )

                            [hit] => 1
                        )
                )
        )
)

The Foo->bar array key is what we're looking at to generate the report, this states hit: 0. The bar key stands out to me here, it has the correct info, but there's no global function named bar() in this file so it shouldn't exist. It looks to me, like Xdebug is doing all the hard work correctly, but has a small bookkeeping error regarding the method name it's keeping track of things under.

Steps To Reproduce

<?php

xdebug_start_code_coverage(XDEBUG_CC_UNUSED | XDEBUG_CC_DEAD_CODE | XDEBUG_CC_BRANCH_CHECK);

class Foo
{
public static function bar(string $input): string
{
return $input;
}
}

$firstClassCallable = Foo::bar(...);
$closureFromCallable = Closure::fromCallable(['Foo', 'bar']);
$anonFunction = fn(string $string) => Foo::bar($string);

$firstClassCallable('testing');
//$closureFromCallable('testing');
//$anonFunction('testing');

$coverage = xdebug_get_code_coverage()[FILE]['functions'];
print_r($coverage);

TagsNo tags attached.
Operating SystemIrrelevant
PHP Version8.2-dev

Activities

derick

2023-05-24 16:04

administrator   ~0006561

I can reproduce this, but in a somewhat different way. I've created a branch/PR with a (failing) test: https://github.com/xdebug/xdebug/pull/889

Issue History

Date Modified Username Field Change
2023-03-05 12:23 sebastian New Issue
2023-05-24 16:04 derick Assigned To => derick
2023-05-24 16:04 derick Status new => confirmed
2023-05-24 16:04 derick Note Added: 0006561
2023-05-24 16:04 derick Target Version => 3.2dev
2023-09-04 11:06 derick Target Version 3.2dev => 3.3dev