- How do I install PestStan in a Laravel project?
- Run `composer require mrpunyapal/peststan --dev` in your Laravel project. Ensure you also have Pest (`pestphp/pest`) and PhpStan (`phpstan/phpstan`) installed. The package integrates automatically with your existing Pest setup.
- Does PestStan work with Laravel’s Eloquent models and Collections?
- PestStan supports Eloquent models and Collections out of the box, but you may need to configure custom PhpStan extensions for complex Laravel-specific types. Check the PhpStan Laravel extension (`nunomaduro/collision`) for additional rules.
- Will PestStan slow down my test suite significantly?
- Running PhpStan on every test file can add overhead, but you can optimize by using Pest’s `--with-stan` flag selectively or running it only in CI. For large suites, consider parallel execution or limiting checks to critical paths.
- Can I use PestStan with Laravel’s service container bindings?
- Yes, PestStan will analyze type safety in your service container bindings, including interfaces, abstract classes, and resolved dependencies. Ensure your container bindings are properly typed to avoid false positives.
- How do I handle false positives in PestStan for Laravel’s dynamic features?
- False positives often occur with magic methods or dynamic properties. Extend PhpStan with Laravel-specific rules or suppress errors using `@phpstan-ignore` in Pest tests. The `nunomaduro/collision` package provides helpful extensions.
- Does PestStan support Laravel 10 and newer versions?
- PestStan is designed to work with modern Laravel versions (10+) and Pest 2.x. Verify compatibility by checking the package’s `composer.json` for Laravel and Pest version constraints before installation.
- Can I integrate PestStan into GitHub Actions for CI/CD?
- Yes, add PestStan to your GitHub Actions workflow by running `./vendor/bin/pest --with-stan` in your test job. Configure it to fail the build on PhpStan errors or warnings, depending on your team’s preferences.
- What’s the difference between PestStan and running PhpStan separately?
- PestStan integrates PhpStan directly into Pest’s execution flow, making it easier to catch type issues during test runs. Running PhpStan separately requires additional configuration and doesn’t leverage Pest’s test isolation features.
- How do I configure PestStan for specific test files or suites?
- Use Pest’s `@type-check` tag to opt into PhpStan checks for specific test files or suites. Alternatively, configure the `--with-stan` flag in your Pest command to run checks selectively or globally.
- Are there alternatives to PestStan for type-checking Pest tests?
- You could use PhpStan directly with a custom script or integrate it via PHPUnit, but PestStan provides a tighter integration with Pest’s modern syntax and Laravel-friendly features, reducing setup complexity.