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.
toExtend, toBeInvokable) complements Laravel’s layered architecture (e.g., DTOs, repositories, services), enabling stricter enforcement of design patterns.composer require --dev), and auto-registration via phpstan/extension-installer reduces manual configuration. Existing Laravel projects using Pest and PHPStan can adopt PestStan with minimal effort.pest.expectation.impossible) may flag legitimate edge cases as errors. Mitigation: Use @phpstan-ignore or baseline adjustments.@var annotations. Risk: Minor developer overhead in edge cases.Pest.php setups (e.g., multi-test-case inheritance) may need explicit peststan.neon overrides. Risk: Low, but requires documentation review.pest.test.emptyClosure for TODOs) must be pre-defined.phpstan --memory-limit=1G to assess trade-offs.TestCase hierarchies (e.g., trait-based)? PestStan’s auto-detection may need manual overrides.it(), expect(), beforeEach()) without runtime modifications.phpstan commands.phpstan/extension-installer is optional but recommended.composer require --dev mrpunyapal/peststan
tests/Pest.php files by default.# phpstan.neon
parameters:
peststan:
testCaseClass: App\Tests\TestCase
pestConfigFiles: [tests/Pest.php, tests/Unit/Pest.php]
phpstan analyse to identify type errors or rule violations.@phpstan-ignore or baseline adjustments.--level=max for strict mode, then relax as needed.--level=5 (strict) to --level=8 (loose). Rules like pest.expectation.impossible are most valuable at higher levels.expect() extensions. Use @var annotations for unsupported assertions.phpstan.neon.phpstan to CI pipelines (e.g., phpstan analyse --level=7).pest.test.emptyClosure) for new tests.@var annotations for complex dynamic properties.^1.0).pest.group.invalidName).peststan.neon settings or ignored rules.@phpstan-ignore usage and type inference patterns.@var for dynamic properties), but complex cases may require IDE tooltips or pair programming.expect()->toBeInstanceOf() chaining).phpstan debug to diagnose configuration issues.pest.expectation.impossible) to guide fixes.phpstan analyse tests/Feature/NewTest.php).--memory-limit=1G or parallel analysis (phpstan --parallel).paths:
tests/Integration:
ignoreErrors:
- pest.test.duplicateDescription
phpstan.neon and vendor/ directory to reduce build times.actions/cache or Laravel Forge’s composer cache.| Failure Mode | Impact | Mitigation |
|---|---|---|
| False positive static errors | Developers ignore PestStan rules. | Use @phpstan-ignore sparingly; review baselines. |
| Auto-detection fails | $this binding or TestCase types incorrect. |
Explicitly set testCaseClass in phpstan.neon. |
| Rule overload | Too many errors slow down development. | Start with --level=5, gradually increase strictness. |
| Dynamic property inference gaps | Union types or complex hooks misanalyzed. | Add @var annotations or simplify property logic. |
| CI timeouts | Analysis too slow for large suites. | Parallelize, cache, or split tests. |
$this binding) in a 30-minute session.How can I help you explore Laravel packages today?