View Issue Details

IDProjectCategoryView StatusLast Update
0001691XdebugCode Coveragepublic2019-08-26 12:37
Reporterxthiago Assigned Toderick  
PrioritynormalSeverityminorReproducibilityalways
Status closedResolutionfixed 
Product Version2.8.0beta1 
Target Version2.8.0devFixed in Version2.8.0beta2 
Summary0001691: Incorrect detection: line executed is marked as not executed
Description

When I was analyzing the code coverage using PHPUnit I saw that ->verifyNow() call below is incorrectly detected as not executed.

<code php>
public static function fromString(string $latitude, string $longitude) : self
{
Assert::lazy()
->that($latitude, 'latitude')->range(self::LATITUDE_RANGE['min'], self::LATITUDE_RANGE['max'])
->that($longitude, 'longitude')->range(self::LONGITUDE_RANGE['min'], self::LONGITUDE_RANGE['max'])
->verifyNow();

    return new self($latitude, $longitude);
}

</code>

The report:

{{https://user-images.githubusercontent.com/720151/61863128-680c8a80-aea5-11e9-8263-fea4152b8719.png}}

It is detected correctly if I a change that the structure of statements to call everything in one line:

<code php>
public static function fromString(string $latitude, string $longitude) : self
{
Assert::lazy()->that($latitude, 'latitude')->range(self::LATITUDE_RANGE['min'], self::LATITUDE_RANGE['max'])->that($longitude, 'longitude')->range(self::LONGITUDE_RANGE['min'], self::LONGITUDE_RANGE['max'])->verifyNow();

    return new self($latitude, $longitude);
}

</code>

{{https://user-images.githubusercontent.com/720151/61863467-0862af00-aea6-11e9-8b09-1bf5b7e20d42.png}}

Or if I split the verifyNow() call to another line:

<code php>
public static function fromString(string $latitude, string $longitude) : self
{
$assertion = Assert::lazy()
->that($latitude, 'latitude')->range(self::LATITUDE_RANGE['min'], self::LATITUDE_RANGE['max'])
->that($longitude, 'longitude')->range(self::LONGITUDE_RANGE['min'], self::LONGITUDE_RANGE['max']);
$assertion->verifyNow();

    return new self($latitude, $longitude);
}

</code>

{{https://user-images.githubusercontent.com/720151/61863607-51b2fe80-aea6-11e9-9aa6-17c51bb91daf.png}}

Steps To Reproduce

Here's the class with the line detected incorrectly: https://github.com/xthiago/php-code-coverage-with-incorrect-line-detection/blob/master/src/Sample.php

Here's a scenario test case using Docker with steps to reproduce: https://github.com/xthiago/php-code-coverage-with-incorrect-line-detection.

Additional Information

PHP 7.4.0beta1
xdebug 2.8.0beta1

Previously I reported the issue on https://github.com/sebastianbergmann/php-code-coverage/issues/687. Now it's closed because they said it's an Xdebug bug.

TagsNo tags attached.
Attached Files
Sample.php (341 bytes)   
<?php

declare(strict_types=1);

namespace Xthiago;

use Assert\Assert;

class Sample
{
    public function __construct(string $latitude, string $longitude)
    {
        Assert::lazy()
            ->that($latitude, 'latitude')->range(-90, 90)
            ->that($longitude, 'longitude')->range(-140, 140)
            ->verifyNow();
    }
}
Sample.php (341 bytes)   
Operating System
PHP Version7.4-dev

Activities

derick

2019-08-02 10:50

administrator   ~0005099

Fixed for the next 2.8 beta. Thanks for your report!

Issue History

Date Modified Username Field Change
2019-08-01 10:27 xthiago New Issue
2019-08-01 10:27 xthiago File Added: Sample.php
2019-08-01 14:07 derick Status new => assigned
2019-08-01 14:07 derick Target Version => 2.8.0dev
2019-08-02 10:50 derick Assigned To => derick
2019-08-02 10:50 derick Status assigned => closed
2019-08-02 10:50 derick Resolution open => fixed
2019-08-02 10:50 derick Fixed in Version => 2.8.0dev
2019-08-02 10:50 derick Note Added: 0005099
2019-08-26 12:37 derick Fixed in Version 2.8.0dev => 2.8.0beta2