| 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:

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

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]

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]

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)
As investigated in infection/infection#1736, coverage for closures doesn't seem to be picked up correctly, when using PHPDBG.
Specifically,
PCOVworks as expected:A coverage report done with
phpdbg -qrrwill instead produce partial coverage:Reproducible example
PHPDBG output
PCOV output
PHPDBG + PCOV = 💥
Note: running
phpdbgwithpcovinstalled will lead to a segfault: