You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
I have a project that uses Mockery, and have both phpstan and psalm running against it.
I'm using this plugin and the phpstan mockery plugin (https://github.com/phpstan/phpstan-mockery) to help reduce the number of errors that have to ignored and/or worked around.
One thing that the phpstan plugin does, that this plugin doesn't seem to, is treating the Mockery\MockInterface as an intersection type when defined with another object:
Interprets Foo|\Mockery\MockInterface in phpDoc so that it results in an intersection type instead of a union type.
After poking around some, I was able to get the plugin to work fine with the Object[method1,method2] syntax of Mockery::mock, as long as the @var User|\Mockery\MockInterface doc block is removed (which seems fine to me, though the phpstan plugin would need to be updated to support that syntax as well, but that's a different issue).
I believe I can override the @var with a @psalm-var though and define it as User&\Mockery\MockeryInterface which seems to make both psalm and phpstan happy in this case. Ideally it would be nice to not need the @var or @psalm-var at all, but I think I'll have to submit a PR to the phpstan mockery plugin project to make that happen.
I'll put together a PR for what I've done for this plugin to accept that Mockery mock syntax though.
I have a project that uses Mockery, and have both phpstan and psalm running against it.
I'm using this plugin and the phpstan mockery plugin (https://github.com/phpstan/phpstan-mockery) to help reduce the number of errors that have to ignored and/or worked around.
One thing that the phpstan plugin does, that this plugin doesn't seem to, is treating the
Mockery\MockInterface
as an intersection type when defined with another object:This allows me to do something like this:
When defining mocks, and then the methods available on both
User
and\Mockery\MockInterface
are available. So when the Mock is later used like so:phpstan won't complain that the
User
class doesn't have theshouldReceive
method. Likewise, this code also won't trigger an error:Since the
User
object does have this method (but\Mockery\MockInterface
) does not.Is this something that could/should be added to this plugin? I can try to take a stab at it if so...
The text was updated successfully, but these errors were encountered: