New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Incorrect coverage reported for last line in loop #589

Closed
andrewnicols opened this Issue Mar 2, 2018 · 2 comments

Comments

2 participants
@andrewnicols

andrewnicols commented Mar 2, 2018

Q A
php-code-coverage version 6.0.1
PHP version 7.1.14
Driver Xdebug 2.6.0 / PHPDBG 0.5.0 (both tested and both show the issue)
Xdebug version (if used) 2.6.0
Installation Method Composer
Usage Method PHPUnit
PHPUnit version (if used) 7.0.2

Basic sample code

<?php

class manager {
    public function get_component_list() {
        return ['a'];
    }

    public function export_user_data() {
        foreach ($this->get_component_list() as $item) {
            if (false) {
                echo "Test\n";
            }
            if (false) {
                echo "Test\n";
            }
            if (false) {
                echo "Test\n";
                echo "Test\n";
            }
        }

        return true;
    }
}

Basic sample testcase

<?php

require_once('manager.php');

class test extends \PHPUnit\Framework\TestCase {
    public function test_export_user_data_unmocked() {
        $manager = new manager();
        $this->assertTrue($manager->export_user_data());
    }
}

Test commands

2040 phpunitcoverbug:master> phpdbg -qrr ./vendor/bin/phpunit --whitelist manager.php --coverage-html coverage/ test.php
PHPUnit 7.0.2 by Sebastian Bergmann and contributors.

.                                                                   1 / 1 (100%)

Time: 23 ms, Memory: 6.00MB

OK (1 test, 1 assertion)

Generating code coverage report in HTML format ... done

XDebug:

2043 phpunitcoverbug:master> xphp71 ./vendor/bin/phpunit --whitelist manager.php --coverage-html coverage/ test.php
PHPUnit 7.0.2 by Sebastian Bergmann and contributors.

.                                                                   1 / 1 (100%)

Time: 48 ms, Memory: 4.00MB

OK (1 test, 1 assertion)

Generating code coverage report in HTML format ... done

Expected result

None of the echo lines are covered

Actual result

The final echo line covered.
Adding another copy of the if test moves which lines are covered.

phpunit-coverage-two

Other notes

Originally replicate against php-code-coverage 5.3.0, PHP 7.1.14, XDebug 2.6.0 and PHPUnit 6.4.4.

@andrewnicols

This comment has been minimized.

andrewnicols commented Mar 2, 2018

After looking into this further I think that this is probably one for @derickr.
I've opened https://bugs.xdebug.org/view.php?id=1530 and provided (failing) testcase there.

Closing this issue as I'm 99% sure it's actually a bug in both xdebug and phpdbg.

@derickr

This comment has been minimized.

derickr commented Mar 3, 2018

It's not an Xdebug issue either, so I've opened: https://bugs.php.net/bug.php?id=76046

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment