- How does PestStan improve type safety in Laravel Pest tests?
- PestStan extends PHPStan to analyze Pest’s `expect()` function, inferring generic types (e.g., `Expectation<string>`) and narrowing types after assertions like `toBeString()` or `toBeInstanceOf()`. This catches type mismatches early, reducing runtime errors in Laravel’s test suite.
- Which Laravel versions and Pest versions does PestStan support?
- PestStan works with any Laravel version using **Pest 3–5** and **PHP 8.2+**. It’s framework-agnostic but integrates seamlessly with Laravel’s Pest-based testing workflows, including TDD/BDD scenarios.
- Do I need to manually configure PestStan in `phpstan.neon`?
- No—if you use `phpstan/extension-installer`, PestStan auto-registers. Otherwise, add `includes: [- vendor/mrpunyapal/peststan/extension.neon]` to your config. No changes to Pest test files are needed.
- Will PestStan break existing Pest tests or require syntax changes?
- PestStan is a **zero-configuration extension** that analyzes existing tests without syntax changes. It only adds static analysis; runtime behavior remains identical. Start with `--level=5` to avoid false positives.
- How does PestStan handle dynamic types (e.g., `expect($dynamicValue)`)?
- PestStan infers types dynamically (e.g., `Expectation<mixed>`) but may flag unsafe assumptions. Use `@var` hints or `@phpstan-ignore-next-line` for truly dynamic cases. Gradually enable stricter checks via `phpstan.neon`.
- Can PestStan reduce false positives in Laravel’s CI pipeline?
- Yes—start by ignoring rules like `pest.expectation.impossible` in `phpstan.neon`, then enable stricter checks incrementally. Run PestStan in CI (not locally) to avoid slow feedback loops, and use `--generate-baseline` for caching.
- Does PestStan work with custom Pest TestCase classes (e.g., `HttpTestCase`)?
- Yes, but auto-detection may need tuning. If using multiple TestCase classes (e.g., `UnitTestCase`, `FeatureTestCase`), explicitly list them in `phpstan.neon` under `parameters.testCaseClasses`.
- What’s the performance impact of PestStan on large Laravel test suites?
- PHPStan adds CPU/memory overhead. For large suites, run PestStan in CI (not locally) and cache results with `--generate-baseline`. Benchmark with a subset of tests first—most teams see <5% CI time increase.
- Are there alternatives to PestStan for type-safe Pest tests?
- No direct alternatives exist yet, but you could use **PHPStan’s built-in rules** (less precise) or **Pest’s `assert()` helpers** with manual type hints. PestStan is the only extension designed specifically for Pest’s dynamic assertions.
- How do I handle false positives when PestStan flags `expect($value)->toBeString()` as unsafe?
- False positives often occur with dynamic values. Use `@var` hints (e.g., `@var string $value`) or `@phpstan-ignore-next-line` temporarily. Refactor tests to narrow types earlier, or adjust `phpstan.neon` to ignore specific rules.