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 match function coverage #904

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

Regression in match function coverage #904

hemberger opened this issue Feb 26, 2022 · 1 comment

Comments

@hemberger
Copy link
Contributor

Q A
php-code-coverage version 9.2.13
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

As recently as php-code-coverage 9.2.11, the builtin match function reported coverage for each matching case. In 9.2.13, the cases are not even marked as coverable. Is this expected behavior? It seems quite useful to me to know which match cases are covered by tests.

Here is an example class:

<?php declare(strict_types=1);

namespace Smr;

class Bla {

    public int $foo;

    public function __construct(string $bar) {
        $this->foo = match ($bar) {
            'a' => 1,
            'b' => 2,
            'c' => 3,
            // Some comments
            default => 4,
        };
    }   

}

And here is the corresponding test:

<?php declare(strict_types=1);

use Smr\Bla;

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

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

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

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

}

Here is the coverage report from 9.2.11:
image
(Note that the tests covering cases 'a', 'b', and default are test_a, test_b, and test_default respectively, as expected.)

And here is the coverage report from 9.2.13:
image

Thanks for your time!

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