Skip to content

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

Closed
@Jean85

Description

@Jean85

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.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions