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

Product Decisions This Supports

  • Enhanced Test Quality & Developer Experience:

    • Adopting PestStan enables stricter type safety in Pest tests, reducing runtime errors and improving IDE autocompletion. This aligns with a roadmap prioritizing reliability and developer productivity in PHP test suites.
    • Supports a shift-left testing strategy by catching type mismatches and logical errors during static analysis (e.g., impossible assertions like expect(42)->toBeString()).
  • Build vs. Buy Decision:

    • Buy: PestStan is a lightweight, MIT-licensed extension with no maintenance overhead. It integrates seamlessly with existing PHPStan setups, avoiding the need to build custom type-checking logic for Pest.
    • Build Alternative: Only consider building if PestStan lacks critical features (e.g., support for custom Pest plugins or niche assertions). Currently, the package covers 90%+ of common use cases.
  • Use Cases:

    • Large-Scale PHP Projects: Ideal for teams using Pest + PHPStan (e.g., Laravel, Symfony) to enforce type safety in tests.
    • Test-Driven Development (TDD): Reduces flaky tests by validating assertions statically.
    • Onboarding: Helps new developers understand expected types and test structures via IDE hints.
    • CI/CD Optimization: Fails fast on type errors, reducing redundant test runs.
  • Roadmap Enablers:

    • Architecture Testing: PestStan’s support for expect()->toExtend(), toBeInvokable(), etc., enables semantic architecture validation in tests (e.g., enforcing final classes or strict types).
    • Dynamic Property Inference: Reduces boilerplate @var annotations, improving maintainability for test suites with complex setup (e.g., factories, mocks).

When to Consider This Package

  • Adopt PestStan if:

    • Your project uses Pest v3+ and PHPStan v2+ (PHP 8.2+).
    • You prioritize type safety in tests and want to catch errors early.
    • Your team relies on IDE tooling (e.g., PHPStorm, VSCode) for autocompletion in test files.
    • You use Pest’s fluent assertions (expect()->toBe...) and want accurate type hints.
    • You need static analysis rules to enforce test best practices (e.g., empty closures, invalid throws()).
  • Look Elsewhere if:

    • You’re using older Pest/PHPStan versions (pre-3.0/2.0). PestStan may not support legacy setups.
    • Your tests are heavily dynamic (e.g., runtime-generated assertions) and static analysis would add little value.
    • You lack PHPStan integration in your CI/CD pipeline. PestStan’s benefits are maximized when paired with static analysis.
    • You need custom Pest plugins not covered by PestStan (e.g., proprietary assertion methods). Extend PestStan or build a custom extension.
    • Your team prefers runtime assertions over static checks (e.g., relying on Pest’s built-in error messages).

How to Pitch It (Stakeholders)

For Executives:

"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:

  • Fewer production bugs from test-related issues.
  • Faster onboarding for new devs (IDE autocompletion + type hints).
  • Lower CI costs by failing fast on type errors.

For Engineering Teams:

*"PestStan bridges Pest and PHPStan to deliver first-class type safety for test assertions. Key benefits:

  1. Accurate Type Inference: expect($user)->toBeInstanceOf(User::class) now works seamlessly with PHPStan.
  2. Static Analysis Rules: Catches anti-patterns like empty test closures, invalid throws(), or redundant assertions before runtime.
  3. $this Binding: Properly types $this in test closures and lifecycle hooks (e.g., beforeEach), eliminating ‘Cannot access property on
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.
terminal42/code-quality-tools
codifyo/ts-generator-bundle
andydefer/laravel-cluster
testo/fiber
mintobit/jobqueue
a4sex/maintenance-bundle
a4sex/entity-date-update
a4sex/client-identifier
a4sex/base-utilites
a4sex/key-value-storage
a4sex/micro-status
chilldev/dependency-injection-extra
datinglibre/datinglibre-app-api
biberltd/corebundle
bricre/symfony-bundle-test
biberltd/logbundle
dominium/http-adapter-bundle
dominium/google-analytics
a4sex/auto-clean-entity
christhompsontldr/laravel-inky