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+.
Enhanced Test Quality & Developer Experience:
expect(42)->toBeString()).Build vs. Buy Decision:
Use Cases:
Roadmap Enablers:
expect()->toExtend(), toBeInvokable(), etc., enables semantic architecture validation in tests (e.g., enforcing final classes or strict types).@var annotations, improving maintainability for test suites with complex setup (e.g., factories, mocks).Adopt PestStan if:
expect()->toBe...) and want accurate type hints.throws()).Look Elsewhere if:
"PestStan supercharges our PHP test suite by adding static type checking to Pest, the modern PHP testing framework. This reduces bugs, speeds up development, and cuts CI costs by catching errors before tests run. For example, it’ll flag impossible assertions like expect(42)->toBeString() during code review—not at runtime. It’s a lightweight, zero-maintenance upgrade that aligns with our investment in PHPStan for type safety. Teams using Pest (like Laravel) will see immediate productivity gains, and it’s free to adopt."
ROI:
*"PestStan bridges Pest and PHPStan to deliver first-class type safety for test assertions. Key benefits:
expect($user)->toBeInstanceOf(User::class) now works seamlessly with PHPStan.throws(), or redundant assertions before runtime.$this Binding: Properly types $this in test closures and lifecycle hooks (e.g., beforeEach), eliminating ‘Cannot access property onHow can I help you explore Laravel packages today?