sebastianbergmann / php-code-coverage

Library that provides collection, processing, and rendering functionality for PHP code coverage information.
BSD 3-Clause "New" or "Revised" License
8.81k stars 373 forks source link

Coverage on not implemented interface #919

Open andrewprofile opened 2 years ago

andrewprofile commented 2 years ago
Q A
php-code-coverage version 9.2.15
PHP version 8.0.9
Driver Xdebug
Xdebug version 3.1.5
Installation Method Composer
Usage Method PHPUnit
PHPUnit version 9.5.20

When I use code coverage in the report I get false-positive information that I partially have un-covered methods from the interface, which is a contract and has no implementation at all in this repository in my case.

image

andrewprofile commented 2 years ago

The problem is caused by this workaround https://github.com/sebastianbergmann/php-code-coverage/blob/fe7247675ceced8048b1cef147bda58e14afe35a/src/StaticAnalysis/IgnoredLinesFindingVisitor.php#L56 which starts ignoring the line and then because this is the infterface in the next condition https://github.com/sebastianbergmann/php-code-coverage/blob/fe7247675ceced8048b1cef147bda58e14afe35a/src/StaticAnalysis/IgnoredLinesFindingVisitor.php#L67 it already returns $node without defining the end of the ignore.

I modified the code and in my case it solved the problem

if ($node instanceof Interface_) {
    $this->ignoredLines = array_merge(
        $this->ignoredLines,
        range($node->getStartLine(), $node->getEndLine())
    );
    return;
}

image

But I don't know if this global change broke something, that's why I didn't create a Pull Request

@sebastianbergmann what do you think?

andrewprofile commented 2 years ago

@sebastianbergmann Could you take a look at it because I don't know whether to give a pull request?

danielgelling commented 1 year ago

We're experiencing the same issue with the following (newer) versions:

Q A
php-code-coverage version 9.2.21 and 9.2.22
PHP version 8.1.13
Driver both PCOV and Xdebug
PCOV version 1.0.11
Xdebug version 3.1.6
Installation Method Composer
Usage Method PHPUnit
PHPUnit version 9.5.25

But with version 9.2.20 everything works as expected.

vstelmakh commented 1 year ago

Same issue for me, some lines from interfaces reported as uncovered, starting from 9.2.21. With 9.2.20 and before it was fine. I guess issue introduced here #964.

Q A
php-code-coverage version 9.2.21
PHP version 8.1.13
Driver Xdebug
Xdebug version 3.2.0
Installation Method Composer
Usage Method PHPUnit
PHPUnit version 9.5.27

For reproducible example see https://github.com/vstelmakh/url-highlight

  1. Clone the repository
  2. Install dependencies: composer install
  3. Run tests with code coverage: XDEBUG_MODE=coverage vendor/bin/phpunit --coverage-clover var/coverage.xml
  4. See var/coverage.xml for results.

Additionally, attaching a coverage.xml part here. It shrieked (to 13 lines) just to display an issue. The same issue is with HTML coverage.

vstelmakh commented 1 year ago

Seems like got fixed. Not reproducible in 9.2.23 for me.

niconoe- commented 1 year ago

Hi. I'm sorry to dig up this issue, but I'm encountering something similar an I didn't want to create a duplicate of it.

The coverage reports a false positive on interfaces when signature of methods are described on multiple lines.

image

You can see the version of CodeCoverage/PHP/PHPUnit I'm using to report this coverage. I'm using XDebug 3.2.0.

Thanks a lot