php-code-coverage icon indicating copy to clipboard operation
php-code-coverage copied to clipboard

Coverage on not implemented interface

Open andrewprofile opened this issue 2 years ago • 6 comments

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 avatar Jun 09 '22 13:06 andrewprofile

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 avatar Jun 09 '22 13:06 andrewprofile

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

andrewprofile avatar Jul 12 '22 08:07 andrewprofile

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.

danielgelling avatar Dec 22 '22 10:12 danielgelling

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 avatar Dec 27 '22 13:12 vstelmakh

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

vstelmakh avatar Jan 05 '23 16:01 vstelmakh

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

niconoe- avatar Feb 15 '23 10:02 niconoe-