View Issue Details
ID | Project | Category | View Status | Date Submitted | Last Update |
---|---|---|---|---|---|
0001851 | Xdebug | Code Coverage | public | 2020-09-16 20:39 | 2020-09-28 14:45 |
Reporter | dvdoug | Assigned To | derick | ||
Priority | normal | Severity | major | Reproducibility | always |
Status | closed | Resolution | fixed | ||
Product Version | 2.9.7 | ||||
Target Version | 2.9.8 | Fixed in Version | 2.9.8 | ||
Summary | 0001851: 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 | <?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); | ||||
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 | ||||
Tags | No tags attached. | ||||
Operating System | Windows 10 | ||||
PHP Version | 7.4.0-7.4.4 | ||||
|
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 |
|
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. |
|
Fixed through https://github.com/xdebug/xdebug/pull/655 |
|
Thanks Derek (btw I didn't receive any email notifications on this, might be broken?) |
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 |