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

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

Closed
Jean85 opened this issue May 22, 2023 · 3 comments
Closed

Comments

@Jean85
Copy link
Contributor

Jean85 commented May 22, 2023

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
Copy link
Contributor Author

Jean85 commented May 22, 2023

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

ondrejmirtes pushed a commit that referenced this issue May 23, 2023
@ondrejmirtes
Copy link
Member

Fixed #186

@github-actions
Copy link

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.

@github-actions github-actions bot locked as resolved and limited conversation to collaborators Jun 24, 2023
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants