View Issue Details

IDProjectCategoryView StatusLast Update
0002164XdebugCode Coveragepublic2023-03-05 15:12
Reportersebastian Assigned To 
PrioritynormalSeveritymajorReproducibilityhave not tried
Status newResolutionopen 
Product Version3.2.0 
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

There are no notes attached to this issue.

Issue History

Date Modified Username Field Change
2023-03-05 12:23 sebastian New Issue