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 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.
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.
directorytree/privacy-filter-classifier
directorytree/privacy-filter
datacore/hub-sdk
develia/commons
cuci/prototurk-sdk
cuci/prototurk-sdk-symfony
develia/geo-bundle
dreamzy/livewire-charts
touchestate-sdk/php-sdk
22h/doctrine-garbage-collection-bundle
agtp/agtp-php
agtp/mod-php
splash/sonata-admin
splash/metadata
splash/openapi
splash/scopes
splash/toolkit
testo/output-teamcity
testo/bridge-symfony
spatie/flare-daemon-runtime