alies-dev/psalm-plugin-pest
Psalm plugin for Pest: types $this in test closures as the configured TestCase (with its traits and beforeEach() properties), resolves expectation and higher-order test chains, narrows types after expect() and accepts Pest's public API.
169
2
| Install | |
|---|---|
composer require alies-dev/psalm-plugin-pest |
|
| Latest Version: | 0.2.3 |
| PHP: | ^8.3 |
| License: | MIT |
| Last Updated: | Oct 20, 2026 |
| Links: | GitHub · Packagist |
Maintainer: alies-dev
Psalm plugin for Pest
Makes Psalm understand Pest tests.
composer require --dev alies-dev/psalm-plugin-pest
vendor/bin/psalm-plugin enable alies-dev/psalm-plugin-pest
Requires PHP 8.3+, Psalm 6.19+ or 7 (including dev-master) and Pest 4 or 5. Your tests/ directory must be in <projectFiles>.
What it does
- Types
$thisin test, hook and dataset closures as the TestCase fromuses()/pest()->extend(), including traits fromuses()/->use(). - Declares
$this->xassigned inbeforeEach()(in the file or intests/Pest.phphooks) for the tests it applies to. - Types
test()with no arguments as the bound TestCase, and resolves higher-order tests likeit('x')->actingAsAdmin(). - Types expectation chains:
->not,->each, higher-order members (expect($user)->name->toBe('Ada')), andexpect($v)asExpectation<T>. - Narrows variables after type assertions:
expect($user)->not->toBeNull()makes$usernon-null. - Stops reporting
InternalMethodon Pest's public API. - Reports
PestHookInDescribeforbeforeAll()/afterAll()insidedescribe(), which Pest rejects when loading the file. - Reports
PestStaticTestClosurefor astaticclosure passed totest(),it(),beforeEach()orafterEach(), since Pest cannot bind$thisto it. - Reports
PestDuplicateTestDescriptionfor a second test with the same description in a file (scoped bydescribe()), which Pest rejects when loading the file. - Reports
PestImpossibleExpectationwhen a type matcher such asexpect(42)->toBeString()can never pass for the value's type.
Known limitations
tests/Pest.phpis looked up next to your Psalm config, and a test file outsidetests/keeps Pest's own types.- Files are parsed, never executed: a boot file with dynamic
uses()calls disables TestCase resolution for the suite. - Custom expectations from
expect()->extend()are still reported. - Narrowing works on plain variables only, not
$this->prop.
License
MIT, see LICENSE.
Related Packages
heyjordanparker/mago-pest
Mago analyzer support for Pest: $this in test closures, dynamic test properties,...
11
0
odinns/phpstan-pest-this
PHPStan extensions to infer Pest closure $this type from test file mappings.
3,060
1
ianrodrigues/pest-plugin-code-quality
Method-level and class-level maintainability limits (complexity, body lines, par...
205
4
soloterm/solo
A Laravel package to run multiple commands at once, to aid in local development.
557,444
1,288
Version History
| Version | Released | PHP | License |
|---|---|---|---|
| 0.2.3 | ^8.3 | MIT | |
| 0.2.2 | ^8.3 | MIT | |
| 0.2.1 | ^8.3 | MIT | |
| 0.2.0 | ^8.3 | MIT | |
| 0.1.0 | ^8.3 | MIT |