View Issue Details

IDProjectCategoryView StatusLast Update
0001922XdebugCode Coveragepublic2020-12-30 16:38
Reporterthierrydraper Assigned Toderick  
PrioritynormalSeverityminorReproducibilityalways
Status closedResolutionfixed 
Product Version3.0.1 
Target Version3.0devFixed in Version3.0.2 
Summary0001922: Code coverage misses array assignment lines
DescriptionSince upgrading to Xdebug 3.0, the code coverage is no longer including the first line in some multi-line assignments.

Running the attached example I would expected 100% code coverage returned, however with Xdebug 3.0.1 it only returns 18 / 21 (missing lines 28, 34 and 43 when put through PHPUnit's --coverage-html). Rolling back to Xdebug 2.9.8 and re-running the test returns 100% code coverage as expected.
Steps To ReproduceRun the example unit test through PHPUnit 8.5.0:
phpunit --coverage-text --coverage-filter=/tmp/Xdebug /tmp/Xdebug/ExampleTest.php
Additional Information$ php -v
PHP 7.4.13 (cli) (built: Nov 24 2020 10:03:34) ( NTS )
Copyright (c) The PHP Group
Zend Engine v3.4.0, Copyright (c) Zend Technologies
    with Zend OPcache v7.4.13, Copyright (c), by Zend Technologies
    with Xdebug v3.0.1, Copyright (c) 2002-2020, by Derick Rethans
TagsNo tags attached.
Operating SystemFedora 33 with httpd and php-fpm
PHP Version7.4.10-7.4.19

Activities

thierrydraper

2020-12-26 12:30

reporter  

ExampleTest.php (1,301 bytes)   
<?php

use PHPUnit\Framework\TestCase;

class ExampleTest extends TestCase
{
    public function testCodeCoverage(): void
    {
        $arr = $this->arrayBuild();
        $this->assertCount(6, $arr);
        $this->assertEquals(0, $arr[0]['num']);
        $this->assertEquals(1, $arr[1]['num']);
        $this->assertEquals(2, $arr[2]['num']);
        $this->assertEquals(42, $arr['string-index']['num']);
        $this->assertEquals('b', $arr['string-index']['sub']['a']);
        $this->assertEquals('scalar', $arr['multiline-scalar-1']);
        $this->assertEquals('scalar', $arr['multiline-scalar-2']);
    }

    protected function arrayBuild(): array
    {
        $arr = [];
        // Append to array.
        $arr[] = [
            'num' => 0,
        ];
        for ($i = 1; $i < 3; $i++) {
            $arr[] = [
                'num' => $i,
            ];
        }
        // Explicit index.
        list($a, $c, $e) = ['b', 'd', 'f'];
        $arr['string-index'] = [
            'num' => 42,
            'sub' => [
                'a' => $a,
                'c' => $c,
                'e' => $e,
            ],
        ];
        // Multi-line assignment
        $arr['multiline-scalar-1']
            = $arr['multiline-scalar-2']
            = 'scalar';
        return $arr;
    }
}
ExampleTest.php (1,301 bytes)   

derick

2020-12-26 14:45

administrator   ~0005619

I think I see the problem, the ASSIGN_DIM opcode isn't overloaded for just coverage, just like ASSIGN_OBJ from 0001910.

derick

2020-12-30 12:33

administrator   ~0005625

https://github.com/xdebug/xdebug/pull/714

Issue History

Date Modified Username Field Change
2020-12-26 12:30 thierrydraper New Issue
2020-12-26 12:30 thierrydraper File Added: ExampleTest.php
2020-12-26 14:45 derick Status new => assigned
2020-12-26 14:45 derick Target Version => 3.0dev
2020-12-26 14:45 derick Description Updated
2020-12-26 14:45 derick Steps to Reproduce Updated
2020-12-26 14:45 derick Additional Information Updated
2020-12-26 14:45 derick Note Added: 0005619
2020-12-30 12:33 derick Summary Code Coverage in Xdebug 3.0 misses lines counted in Xdebug 2.9 => Code coverage misses array assignment lines
2020-12-30 12:33 derick Note Added: 0005625
2020-12-30 16:38 derick Assigned To => derick
2020-12-30 16:38 derick Status assigned => closed
2020-12-30 16:38 derick Resolution open => fixed
2020-12-30 16:38 derick Fixed in Version => 3.0.2