Skip to content
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

Coverage not working on closures in PHPDBG #945

Closed
Ocramius opened this issue Oct 11, 2022 · 5 comments
Closed

Coverage not working on closures in PHPDBG #945

Ocramius opened this issue Oct 11, 2022 · 5 comments

Comments

@Ocramius
Copy link
Contributor

Q A
php-code-coverage version 9.2.17
PHP version 8.1.10
Driver PHPDBG
PCOV version (if used) 1.0.11
Xdebug version (if used)
Installation Method Composer
Usage Method PHPUnit
PHPUnit version (if used) 9.5.25

As investigated in infection/infection#1736, coverage for closures doesn't seem to be picked up correctly, when using PHPDBG.

Specifically, PCOV works as expected:

Selection_1052

A coverage report done with phpdbg -qrr will instead produce partial coverage:

Selection_1051

Reproducible example

<?php

declare(strict_types=1);

final class Foo
{
    /** @return callable(): int */
    function make(): callable
    {
        return static function (): int {
            return 1;
        };
    }
}
<?php

declare(strict_types=1);

require_once __DIR__ . '/../../src/Foo.php';

/** @covers Foo */
final class FooTest extends \PHPUnit\Framework\TestCase
{
    function testClosure(): void
    {
        self::assertSame(1, (new Foo())->make()());
    }
}

PHPDBG output

❯ phpdbg -qrr ./vendor/bin/phpunit --coverage-html=coverage --filter=Foo
PHPUnit 9.5.25 #StandWithUkraine

.                                                                   1 / 1 (100%)

Time: 00:00.140, Memory: 50.00 MB

OK (1 test, 1 assertion)

Generating code coverage report in HTML format ... done [00:00.812]

Selection_1053

PCOV output

❯ ./vendor/bin/phpunit --coverage-html=coverage --filter=Foo
PHPUnit 9.5.25 #StandWithUkraine

.                                                                   1 / 1 (100%)

Time: 00:00.053, Memory: 40.00 MB

OK (1 test, 1 assertion)

Generating code coverage report in HTML format ... done [00:00.708]

Selection_1054

PHPDBG + PCOV = 💥

Note: running phpdbg with pcov installed will lead to a segfault:

❯ phpdbg -qrr ./vendor/bin/phpunit --coverage-html=coverage --filter=Foo
PHPUnit 9.5.25 #StandWithUkraine

Segmentation fault (core dumped)
@Ocramius
Copy link
Contributor Author

Note: I reported this here, because I don't know if the problem is in phpdbg or in phpunit/php-code-coverage.

I don't really know the underlying protocol, so any help is welcome 👍

@sebastianbergmann
Copy link
Owner

I have never used PHPDBG in production and can only recommend to not use it.

Use PCOV if you only need line coverage and Xdebug if you also want branch and path coverage.

The code coverage functionality provided by PHPDBG is not really maintained, as far as I know. To be honest, the right thing to do would probably be to remove support for it from this library.

@Ocramius
Copy link
Contributor Author

Makes sense: I used phpdbg because it comes with php-src, and I didn't want to add more dependencies to my stack (in general), but I can live with this decision, and adapt to it long-term 👍

@sebastianbergmann
Copy link
Owner

Removed support for PHPDBG in c304be7 for php-code-coverage v10 (to be released alongside PHPUnit 10 in February 2023).

@Ocramius
Copy link
Contributor Author

That was quick and decisive 💪

I'll make sure to upgrade my downstream projects before PHPUnit 10 hits us :)

Ocramius added a commit to Ocramius/laminas-continuous-integration-action that referenced this issue Feb 22, 2023
This is a potential breaking change, but note that PHPUnit v10 no longer
supports PHPDBG for coverage, which was the only use-case for PHPDBG in
this container, thus far.

We instead install `pcov`, which is considered precise enough for coverage
reports by PHPUnit.

Fixes laminas#130

Ref: laminas#130
Ref: sebastianbergmann/php-code-coverage#945
Ref: sebastianbergmann/php-code-coverage@c304be7
uzibhalepu added a commit to uzibhalepu/BackwardCompatibilityCheck that referenced this issue Aug 6, 2024
This patch reduces code size, therefore leading to
generally lower scores.

Until we completely switch to `pcov` and the upstream
issues with `sebastianbergmann/php-code-coverage`
are resolved, we will keep having sub-100% mutation
test scores.

Ref: sebastianbergmann/php-code-coverage#945
Ref: sebastianbergmann/php-code-coverage@c304be7
Ref: laminas/laminas-continuous-integration-action#130
Ref: sebastianbergmann/php-code-coverage#953
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants