-
Notifications
You must be signed in to change notification settings - Fork 48
Return intersection type from Generator::getMock() #32
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
Comments
I have the same problem here. When using mocks in PHPUnit like
PHPStan complains like
I am not sure how to tell PHPStan that In the documentation states:
Does it mean I have to add |
@k00ni Just tried your problem and couldn't reproduce it. This works without a problem: <?php
class Foo extends \PHPUnit\Framework\TestCase
{
public function testBlabla(): void
{
$mock = $this->getMockBuilder(\stdClass::class)->disableOriginalConstructor()->getMock();
$this->doFoo($mock);
}
private function doFoo(\stdClass $stdClass): void
{
}
} No errors on max level. In order to help you, please state:
|
@Stadly You can solve your problem by adding custom stub files https://phpstan.org/user-guide/stub-files to your project, or by contributing generic annotations to PHPUnit itself. I don't plan to address it in phpstan/phpstan-phpunit, because the class in PHPUnit is marked as |
I wanted to provide a demo showing my problem, but after I set it up, I found out, that I actually ran PHPStan Anyway, thank you for the feedback. |
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. |
The easiest way to create mock objects outside of a test case is through
PHPUnit\Framework\MockObject\Generator::getMock()
. This method does not return intersection types, likePHPUnit\Framework\MockObject\MockBuilder::getMock()
andPHPUnit\Framework\TestCase::createMock()
does.Example:
The text was updated successfully, but these errors were encountered: