Search by

psalm / plugin-phpunit

muglugweirdan

Psalm plugin for PHPUnit

Package info

github.com/psalm/psalm-plugin-phpunit

Language:Gherkin

Type:psalm-plugin

pkg:composer/psalm/plugin-phpunit

Statistics

Installs: 26 296 005

Dependents: 1 137

Suggesters: 0

Stars: 79

Open Issues: 16

0.22.0 2026-11-08 23:44 UTC

README

Psalm    PHPUnit

Psalm PHPUnit plugin

CI Type coverage

Teaches Psalm the conventions of PHPUnit, so analysing your test suite stops producing false positives.

Installation

Psalm 7:

# nothing to install.
# The plugin ships with Psalm and is enabled automatically when your `composer.json` requires `phpunit/phpunit`

(see loadLibraryPlugins).

Psalm 6 and older:

composer require --dev psalm/plugin-phpunit
vendor/bin/psalm-plugin enable psalm/plugin-phpunit

Features

  • Properties initialized in setUp() or a @before / #[Before] method count as initialized, so no false MissingConstructor.
  • Data providers are validated: the provider exists, is public static (InvalidDataProvider), returns an iterable, and its datasets match the parameters of the test method.
  • Test methods, their data providers, and TestCase classes are not reported as unused code.
  • Statements after $this->expectException() and its siblings are not reported as UnusedFunctionCall, UnusedMethodCall or MissingThrowsDocblock.
  • Exceptions declared by PHPUnit's own API (assertions, createMock(), createStub() and so on) are not reported as MissingThrowsDocblock. Exceptions in your <ignoreExceptions> stay ignored.
  • $this->prophesize(Foo::class) is typed as ObjectProphecy<Foo>, and magic calls on it resolve to MethodProphecy.
  • assertNotEmpty($x) narrows $x to its non-empty type (?Customer becomes Customer, list<int>|null becomes non-empty-list<int>).

License

MIT