Weave Code
Code Weaver
Helps Laravel developers discover, compare, and choose open-source packages. See popularity, security, maintainers, and scores at a glance to make better decisions.
Feedback
Share your thoughts, report bugs, or suggest improvements.
Subject
Message

Peststan Laravel Package

mrpunyapal/peststan

PHPStan extension for Pest PHP. Adds generic typing for expect(), type-narrowing assertions, type-safe and() chaining, correct $this binding in test closures, and accurate return types for Pest functions. Supports Pest 3–5 on PHP 8.2+.

View on GitHub
Deep Wiki
Context7

PhpStan support for Pest

Frequently asked questions about Peststan
How does PestStan improve type safety in Laravel Pest tests?
PestStan adds PHPStan support for Pest’s `expect()` function, enabling generic typing (e.g., `Expectation<string>`) and type narrowing after assertions like `toBeString()` or `toBeInstanceOf()`. This ensures static analysis catches type mismatches early, reducing runtime errors in Laravel’s test suites.
Will PestStan work with Laravel’s TestCase or custom test classes?
Yes, PestStan integrates out-of-the-box with Laravel’s `TestCase` and custom test classes. It auto-detects Pest’s configuration and enforces type safety across all test methods, including those extending Laravel’s base test classes.
What Laravel/Pest versions does PestStan support?
PestStan supports Pest 3.0–5.0 and Laravel projects using Pest as their testing framework. It requires PHP 8.2+ and PHPStan 2.0+, so ensure your Laravel app meets these baseline requirements before installation.
Do I need to modify existing Pest tests to use PestStan?
No modifications are needed—PestStan works passively by enhancing PHPStan’s static analysis. Your existing test logic remains unchanged, but you’ll gain type safety for `expect()` calls, `$this` binding, and Pest function return types automatically.
How do I configure PestStan if I don’t use phpstan/extension-installer?
Add this to your `phpstan.neon` file: `includes: - vendor/mrpunyapal/peststan/extension.neon`. If PestStan doesn’t detect your test classes, explicitly set `testCaseClass` in the extension’s NEON config to match your Laravel test case class.
Will PestStan slow down my CI/CD pipeline?
No, PestStan runs only during static analysis (not at runtime) and adds minimal overhead. PHPStan’s incremental analysis ensures reprocessing large Laravel test suites remains efficient, even with hundreds of test files.
How do I handle false positives in type narrowing (e.g., dynamic factory calls)?
Use `@var` annotations for complex cases, like `@var User|string $value`. For persistent issues, suppress rules with `@phpstan-ignore pest.test.staticClosure` or adjust PHPStan’s baseline to exclude problematic tests temporarily.
Can PestStan enforce stricter rules like `pest.expectation.impossible` in CI?
Yes, enable stricter rules in your CI’s `phpstan.neon` by adding `level: 8` (or higher) and including PestStan’s extension. Start with `level: 5` locally to avoid disrupting development workflows.
Are there alternatives to PestStan for type-safe Pest tests?
For PHPStan integration, PestStan is the only dedicated extension. Alternatives include using Psalm with Pest (via `vimeo/psalm`), but PestStan provides deeper Pest-specific type support, like `$this` binding and `and()` chaining, tailored for Laravel’s testing ecosystem.
How do I test PestStan’s effectiveness in a Laravel project?
Run `phpstan analyse` and check for new type errors in Pest tests. Focus on `expect()` calls and assertion chains—if PHPStan flags inconsistencies, they’re likely genuine issues. Use the `--error-format=json` flag to parse results programmatically for CI integration.
Weaver

How can I help you explore Laravel packages today?

Conversation history is not saved when not logged in.
Prompt
Add packages to context
No packages found.
terminal42/code-quality-tools
codifyo/ts-generator-bundle
andydefer/laravel-cluster
testo/fiber
mintobit/jobqueue
a4sex/maintenance-bundle
a4sex/entity-date-update
a4sex/client-identifier
a4sex/base-utilites
a4sex/key-value-storage
a4sex/micro-status
chilldev/dependency-injection-extra
datinglibre/datinglibre-app-api
biberltd/corebundle
bricre/symfony-bundle-test
biberltd/logbundle
dominium/http-adapter-bundle
dominium/google-analytics
a4sex/auto-clean-entity
christhompsontldr/laravel-inky