Download the PHP package odinns/phpstan-pest-this without Composer
On this page you can find all versions of the php package odinns/phpstan-pest-this. It is possible to download/install these versions without Composer. Possible dependencies are resolved automatically.
Download odinns/phpstan-pest-this
More information about odinns/phpstan-pest-this
Files in odinns/phpstan-pest-this
Package phpstan-pest-this
Short Description PHPStan extensions to infer Pest closure $this type from test file mappings.
License MIT
Homepage https://github.com/odinns/phpstan-pest-this
Informations about the package phpstan-pest-this
phpstan-pest-this
PHPStan extensions that infer Pest closure $this type from configurable test-path mappings.
Why
Pest binds test closures at runtime, while PHPStan analyzes code statically.
Without extra help, closure $this is commonly inferred as PHPUnit\Framework\TestCase, which can produce false positives in Pest suites.
Installation
Quick setup
Add the extension to your PHPStan config:
The extension does not provide default test case mappings. Configure how file paths map to your Pest base test case classes:
This is the common Laravel/Pest setup where feature and unit tests share Tests\TestCase.
If your project uses separate base test cases, map the more specific paths explicitly:
pathContains is a substring match against the analyzed file path. The first matching mapping wins.
Supported Pest calls
- Function calls:
it(...),test(...),beforeEach(...),afterEach(...) - Fluent hooks:
uses(...)->beforeEach(...),uses(...)->afterEach(...)
Optional: Generate a PHPStan proxy test case
If your base test case has protected assertion helpers, PHPStan may flag visibility errors from Pest closures. Use the included generator to create a static-analysis-only proxy class with public wrappers.
After installation:
While developing this package locally:
Then map the relevant directory to the generated proxy:
This proxy only affects static analysis. It does not change Pest runtime behavior.
Limitations
- The extension resolves closure
$thistype only. - It does not infer dynamic properties automatically; declare those on your test case/traits.
- Mapping is path-substring based, so very broad patterns can match unintentionally.
Development
Troubleshooting
- No effect in analysis: confirm
extension.neonis included in your PHPStan config. - Wrong inferred class: ensure mapping order is specific to broad (first match wins).
- Generator not found: use
vendor/bin/generate-pest-proxy.phpafter install orphp tools/generate-pest-proxy.phpin this repository.
Versioning
This package follows SemVer from 1.0.0 onward. Composer versions come from Git tags, not a version field in composer.json.
Contributing
Keep changes narrow. This package teaches PHPStan about Pest closure $this; it should not grow runtime Pest behavior or framework glue.
Run composer check before opening a PR.
Security
Report security issues privately through GitHub Security Advisories:
https://github.com/odinns/phpstan-pest-this/security/advisories/new
Please do not open public issues for security reports.
Changelog
See CHANGELOG.md for release notes.
License
MIT