phpstan / phpstan-phpunit

PHPUnit extensions and rules for PHPStan
MIT License
468 stars 47 forks source link

assertInstanceOf doesn't refine type when used with generic class-string #185

Closed Jean85 closed 1 year ago

Jean85 commented 1 year ago

I want to implement this method in my testcase:

class BaseTestCase extends \PHPUnit\Framework\TestCase
{
    /**
     * @template T of object
     *
     * @param class-string<T> $class
     *
     * @return T
     */
    protected function fetch(string $class): object
    {
        $message = $this->fetch(); // returns object of unknown class

        $this->assertInstanceOf($class, $message, 'Message is not of the expected type');

        return $firstMessage;
    }
}

but this doesn't seem to work.

Jean85 commented 1 year ago

I hope to have recreated a correct regression test for this in #186

ondrejmirtes commented 1 year ago

Fixed https://github.com/phpstan/phpstan-phpunit/pull/186

github-actions[bot] commented 1 year ago

This thread has been automatically locked since there has not been any recent activity after it was closed. Please open a new issue for related bugs.