mrpunyapal/peststan
PestStan integrates PHPStan with the Pest testing framework, making static analysis fit naturally into your test workflow. Adds Pest-friendly configuration and helpers so you can run PHPStan on your codebase with minimal setup.
Enhanced Test Quality & Developer Experience:
expect($user)->toBeInstanceOf(User::class)).Build vs. Buy Decision:
Roadmap Priorities:
$this binding, dynamic property types).toExtend(), toBeInvokable()) with full PHPStan type support for design validation.Use Cases:
expect($response)->toBeJson()->json('data')->toBeArray()).Adopt PestStan if:
toBeString() on an int at analysis time).expect() chains, $this binding).$this->user = User::factory()->create()) and need type inference.Look Elsewhere if:
*"PestStan supercharges our test suite by eliminating type-related bugs before they reach production. Think of it as static analysis for assertions—just like how PHPStan catches type errors in code, PestStan does the same for tests. This reduces:
toBeString() on an int at analysis time).$this binding in test hooks).expect() chains).For a one-time setup cost (adding a Composer dependency), we gain proactive test quality—critical for scaling our test suite as we grow. Teams using Pest + PHPStan (like Laravel) already rely on this; we’re just adopting a battle-tested extension."*
*"PestStan bridges the gap between Pest’s expressive syntax and PHPStan’s type precision. Key wins:
expect($value)->toBeString() tells PHPStan the value is a string, enabling safer chains like $value->strlen().@var annotations for $this->user = User::factory()—PHPStan auto-detects types from beforeEach hooks.it('test', fn() => {})).expect(42)->toBeString()).$this usage in beforeAll() (which runs statically).toExtend(), toBeInvokable(), etc., with accurate return types.Setup:
composer require --dev mrpunyapal/peststan
Works with phpstan/extension-installer or manual phpstan.neon config. Zero runtime overhead—pure static analysis.
Trade-offs:
Next Steps:
composer.json (dev dependency).phpstan analyse tests to see immediate type improvements.phpstan.neon (e.g., pest.test.emptyClosure)."*How can I help you explore Laravel packages today?