A Psalm plugin for PHPUnit (requires Psalm v4+).
Psalm does not understand PHPUnit conventions on its own. This plugin makes Psalm aware of them, so static analysis of your test suite stops flooding you with false positives.
- Silences false
MissingConstructoron stateful test cases. Properties initialized insetUp()or a@before/#[Before]method are recognized as initialized. - Validates data providers. It checks that a referenced provider exists, returns an
iterable(array, generator, or object), and that each dataset shape matches the parameters of the test method it feeds (types, count, optional offsets, variadic params, defaults). - Reports broken providers. Missing providers, wrong return types, mismatched dataset types, and providers returning
nullare flagged before the suite ever runs. - Fixes unused-code detection for tests. Test methods, providers referenced from docblocks or attributes, and
TestCasedescendants are no longer reported as unused, while genuinely dead test helpers still are. - Types
prophesize().$this->prophesize(Foo::class)is inferred asObjectProphecy<Foo>, so calls on the prophecy are type-checked.
composer require --dev psalm/plugin-phpunit
vendor/bin/psalm-plugin enable psalm/plugin-phpunit