psalm/plugin-mockery
Adds Psalm static analysis support for the Mockery testing framework. Improves type inference and understanding of mocked objects and expectations in PHPUnit-style tests. Install via Composer and enable with psalm-plugin for better mock-related diagnostics.
Install the plugin and enable it in one command sequence:
composer require --dev "psalm/plugin-mockery"
./vendor/bin/psalm-plugin enable psalm/plugin-mockery
That’s it — no config changes needed. Run ./vendor/bin/psalm and observe improved type inference: Mockery::mock(UserRepository::class) now returns UserRepository&Mockery\MockInterface instead of mixed. Your first win? No more @var docblocks like /** @var Mockery\MockInterface&UserRepository $mock */ — Psalm infers them automatically in tests.
$mock = Mockery::mock(UserService::class);$mock is both UserService and Mockery\MockInterface, enabling safe method calls and accurate type checks.$mock = Mockery::mock(UserService::class);
$mock->shouldReceive('handle')->once()->andReturn(true);
// Psalm keeps $mock typed as UserService&Mockery\MockInterface
Mockery::spy() — Psalm correctly infers Mockery\MockInterface&YourClass and validates shouldHaveReceived() usage against the real interface.mockery/mockery ≥1.0. Older versions (e.g., 0.9.x) won’t benefit from new-style typing — and may cause incorrect inference.Mockery::mock(Service::class, [$arg1, $arg2])), Psalm may widen types if args lack precise types. Provide narrow constructor hints or use @phpstan-param in docblocks.spy()) lack full expectation-type inference — avoid deep chaining like $spy->shouldHaveReceived()->once()->with(...) without splitting into steps.Mockery::on(fn() => ...) often loses return type context. Suppress cautiously with @psalm-suppress if no better alternative exists.noDocblockTypes rules — the plugin still infers types even without docblocks, but if you omit @var entirely, ensure your Psalm config doesn’t reject native intersection types.How can I help you explore Laravel packages today?