Skip to content
This repository was archived by the owner on Jul 26, 2021. It is now read-only.
This repository was archived by the owner on Jul 26, 2021. It is now read-only.

Class with method that uses anonymous class is not processed correctly #93

@t0mmy742

Description

@t0mmy742
Q A
php-code-coverage version 8.0.1
PHP version 7.4.5
Driver Xdebug (pcov also)
Xdebug version (if used) 2.9.4
Installation Method Composer
Usage Method PHPUnit
PHPUnit version (if used) 9.1.4

src/PhpAnonym.php

class PhpAnonym
{
    private $field;

    public function __construct(int $field)
    {
        $this->field = $field;
    }

    public function funcOne(): int
    {
        return $this->field;
    }

    public function funcTwo(): int
    {
        $cls = new class(42) {
            private $num;

            public function __construct(int $num)
            {
                $this->num = $num;
            }

            public function getNum(): int
            {
                return $this->num;
            }
        };

        return $cls->getNum();
    }
}

src/PhpAnonymTest.php

class PhpAnonymTest extends \PHPUnit\Framework\TestCase
{
    public function testFuncOne(): void
    {
        $phpAnonym = new PhpAnonym(42);
        $this->assertSame(42, $phpAnonym->funcOne());
    }

    public function testFuncTwo(): void
    {
        $phpAnonym = new PhpAnonym(1234);
        $this->assertSame(42, $phpAnonym->funcTwo());
    }
}

Coverage HTML

1
2

If funcTwo is the first function of the class, it seems like there is no problem.

Metadata

Metadata

Labels

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions