View Issue Details

IDProjectCategoryView StatusLast Update
0001851XdebugCode Coveragepublic2020-09-28 14:45
Reporterdvdoug Assigned Toderick  
PrioritynormalSeveritymajorReproducibilityalways
Status closedResolutionfixed 
Product Version2.9.7 
Target Version2.9.8Fixed in Version2.9.8 
Summary0001851: Paths are not counted as coveraged with loops calling function
Description

In the attached testcase, the importUserRecords() method is called. However, the path data reports [hit] => 0 for each and every path. This seems impossible, 1 of them must have been taken.

Steps To Reproduce

<pre>
<?php

xdebug_start_code_coverage(XDEBUG_CC_UNUSED | XDEBUG_CC_DEAD_CODE | XDEBUG_CC_BRANCH_CHECK);

class NPSRepository
{
/* @var PDO /
private $pdo;

public function __construct(PDO $pdo)
{
    $this->pdo = $pdo;
    $this->pdo->exec('CREATE TABLE np_score(user_id INTEGER NOT NULL, score INTEGER NOT NULL);');
}

public function importUserRecords(array $records): void
{
    $statement = $this->pdo->prepare('INSERT INTO np_score(user_id, score) VALUES (:userId, :score)');
    foreach ($records as $userId => $score) {
        $statement->bindValue('userId', $userId, PDO::PARAM_INT);
        $statement->bindValue('score', $score, PDO::PARAM_INT);
        $statement->execute();
    }
}

}

$pdo = new PDO('sqlite::memory:', null, null, [PDO::ATTR_ERRMODE => PDO::ERRMODE_EXCEPTION]);
$repository = new NPSRepository($pdo);

$repository->importUserRecords([1,1]);

$coverage = xdebug_get_code_coverage()[FILE]['functions']['NPSRepository->importUserRecords'];
print_r($coverage);
</pre>

Additional Information

Initially reproduced on PHP 7.4.9/Xdebug 2.9.6 but I have confirmed that 7.4.10/2.9.7 still exhibit the issue

TagsNo tags attached.
Operating SystemWindows 10
PHP Version7.4.0-7.4.4

Activities

dvdoug

2020-09-16 20:44

reporter   ~0005460

Last edited: 2020-09-25 08:05

<pre>
NPSRepository->__construct

  • branches
    • 00; OP: 00-11; line: 07-11 HIT; out1: EX X
  • paths
    • 0: HIT

NPSRepository->importUserRecords

  • branches
    • 00; OP: 00-09; line: 13-16 HIT; out1: 10 HIT; out2: 28 X
    • 10; OP: 10-10; line: 16-16 HIT; out1: 11 HIT; out2: 28 HIT
    • 11; OP: 11-27; line: 16-16 HIT; out1: 10 HIT
    • 28; OP: 28-30; line: 16-21 HIT; out1: EX X
  • paths
    • 0 10 11 10 28: X
    • 0 10 28: X
    • 0 28: X

{main}

  • branches
    • 00; OP: 00-18; line: 05-29 HIT; out1: EX X
  • paths
    • 0: HIT
      </pre>

derick

2020-09-25 08:08

administrator   ~0005466

The information for branches is mostly correct, but for some reason it doesn't see a through path because the "HIT" for "EX" for branch 28 is missing.

derick

2020-09-25 11:41

administrator   ~0005467

Fixed through https://github.com/xdebug/xdebug/pull/655

dvdoug

2020-09-28 14:45

reporter   ~0005468

Thanks Derek (btw I didn't receive any email notifications on this, might be broken?)

Issue History

Date Modified Username Field Change
2020-09-16 20:39 dvdoug New Issue
2020-09-16 20:44 dvdoug Note Added: 0005460
2020-09-25 08:03 derick Assigned To => derick
2020-09-25 08:03 derick Status new => confirmed
2020-09-25 08:05 derick Note Edited: 0005460
2020-09-25 08:06 derick Steps to Reproduce Updated
2020-09-25 08:08 derick Note Added: 0005466
2020-09-25 10:21 derick Target Version => 2.9.8
2020-09-25 10:21 derick Summary Path coverage reports 0 paths taken even though method is executed => Paths are not counted as coveraged with loops calling function
2020-09-25 10:39 derick Target Version 2.9.8 => 3.0.0beta1
2020-09-25 11:41 derick Status confirmed => closed
2020-09-25 11:41 derick Resolution open => fixed
2020-09-25 11:41 derick Fixed in Version => 3.0.0beta1
2020-09-25 11:41 derick Note Added: 0005467
2020-09-25 23:06 derick Fixed in Version 3.0.0beta1 => 2.9.8
2020-09-25 23:06 derick Target Version 3.0.0beta1 => 2.9.8
2020-09-28 14:45 dvdoug Note Added: 0005468