Skip to content

Regression in empty constructor coverage #905

@hemberger

Description

@hemberger
Q A
php-code-coverage version 9.2.11+
PHP version 8.1.3
Driver Xdebug
Xdebug version (if used) 3.1.3
Installation Method Composer
Usage Method PHPUnit
PHPUnit version (if used) 9.5.14

Coverage of empty constructors has changed between versions 9.2.10 and 9.2.11, and now they are no longer coverable code. In some sense this is not unreasonable, because they are empty after all, but I'm not sure if this was an intentional change. I kind of prefer that they be coverable, since it is still code that can be executed.

Here is an example class:

<?php declare(strict_types=1);

namespace Smr;

class Bla {

    public function __construct(
        public string $foo,
    ) {}

}

And the test that covers it:

<?php declare(strict_types=1);

use Smr\Bla;

/**
 * @covers Smr\Bla
 */
class BlaTest extends \PHPUnit\Framework\TestCase {

    public function test_ctor() : void {
        $bla = new Bla('a');
        self::assertSame('a', $bla->foo);
    }   

}

Here is the coverage report in 9.2.10:
image

Here is the coverage report in 9.2.11 (note that we get the same report in 9.2.13):
image

Thanks again for your time!

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions