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

Regression in empty constructor coverage #905

Closed
hemberger opened this issue Feb 26, 2022 · 1 comment
Closed

Regression in empty constructor coverage #905

hemberger opened this issue Feb 26, 2022 · 1 comment

Comments

@hemberger
Copy link
Contributor

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!

@sebastianbergmann
Copy link
Owner

CC @Slamdunk

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