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
False-positive: PhpUnit mocks support #1053
Comments
This is better suited for a plugin, I believe. @muglug , would it be possible to declare a generic like this: /**
* @template T
* @template-typeof T $class
* @param class-string $class
* @return MockObject&T
*/
public function getMock($class) {} ? Last time I checked, intersection types did not accept type parameters. |
Oh, if not that's a bug - marking as such. |
That bug was fixed in f7a37d0 @kalessil for the moment we don't have a plugin system that supports stubs (and I don't want to support external packages natively), so you'll have to add the stub file yourself: Get it here: And update your config with <stubs>
<file name="path/to/phpunit.php" />
</stubs> Also make sure I've just tagged a release that includes the fix above: https://github.com/vimeo/psalm/releases/tag/2.0.16 |
Awesome, thank you @muglug! I'll test it on Monday (the codebase is on my work machine, but I'm eager to test). |
Checking. Meanwhile phive complains:
|
@muglug: awesome work - works like a charm. Many thanks! Now I need only possibility to get the release via phive and it goes into our pipeline! |
Psalm V3 now supports PHPUnit mocks a bit better via a plugin: https://packagist.org/packages/psalm/plugin-phpunit With Psalm 3, run
If you use mockery, that's also handled:
|
Awesome, thank you for an update @muglug. May I also gently push for re-enabling phive distribution (the signature file is missing, since v1.1.9 so I have to experiment with newer version while CI running on a outdated version). |
Inside PhpUnit test cases, following code (simplified) is triggering
ERROR: InvalidArgument - ... - Argument 1 of Service::__construct expects Clazz, PHPUnit\Framework\MockObject\MockObject provided
The psalm config generated for level 1. My expectation is that psalm is aware of PhpUnit mocks.
The text was updated successfully, but these errors were encountered: