- How do I integrate Psalm static analysis into Laravel’s PHPUnit/Pest test suite?
- Use `phpyh/psalm-tester` to write `.phpt` files with `--FILE--` and `--EXPECT--` sections, then run them via PHPUnit. For example, create a test class extending `TestCase` and use `PsalmTester::test()` with `StaticAnalysisTest::fromPhptFile()`. This works alongside Laravel’s existing test ecosystem.
- Does this package support Laravel-specific Psalm configurations (e.g., Facade stubs)?
- The package is agnostic to Laravel-specific configurations but can integrate with plugins like `psalm-plugin-laravel`. You’ll need to manually configure Psalm’s `psalm.json` or use `--ARGS--` in `.phpt` files to include Laravel-specific rules. No built-in Laravel support exists yet.
- Can I run Psalm tests in CI/CD pipelines without manual baseline updates?
- Yes, use `assertErrorsMatchBaseline()` to compare Psalm output against a stored baseline. This reduces manual intervention in CI/CD, though you may still need occasional updates if Psalm’s error messages change (e.g., new rule versions).
- What Laravel versions and Psalm versions does this package support?
- The package works with any Laravel version (as it’s framework-agnostic) but requires Psalm 4.x or 5.x. Psalm 6.x support is untested and may require updates. Ensure your `composer.json` aligns with your Psalm version constraints.
- How do I customize Psalm arguments for specific tests or globally?
- Set default arguments via `PsalmTester::create(defaultArguments: '--config=my_config.xml')`. Override per-test using `--ARGS--` in `.phpt` files. This flexibility lets you target specific Psalm rules or configurations without modifying the global setup.
- Will this slow down my CI pipeline significantly?
- Running Psalm in tests adds ~5–15 seconds per run, depending on codebase size. Mitigate this by caching results or running tests in parallel (though parallelization isn’t supported in the initial release). For large projects, consider running Psalm separately in CI.
- How do I handle false positives in Psalm tests for Laravel’s dynamic features (e.g., Facades)?
- Use `--ARGS--` to include Laravel-specific Psalm plugins (e.g., `psalm-plugin-laravel`) or suppress errors via `@psalm-suppress` in code. The baseline comparison feature helps track regressions, but manual tuning may still be needed for complex Laravel patterns.
- Can I integrate this with Laravel Forge/Envoyer for deployment-time validation?
- Yes, use Artisan commands (e.g., `php artisan psalm:test`) or test events to run Psalm checks before deployments. The package’s CLI-friendly design makes it easy to hook into Forge/Envoyer scripts for pre-deployment validation.
- Are there alternatives to `phpyh/psalm-tester` for Psalm in Laravel?
- Alternatives include running Psalm directly via `php vendor/bin/psalm` or using `roave/security-advisories` for dependency checks. However, `phpyh/psalm-tester` uniquely integrates Psalm assertions into PHPUnit/Pest, making it ideal for test-driven workflows in Laravel.
- How do I update the baseline if Psalm’s error messages change?
- Manually update the baseline by re-running tests with `--update-baseline` (if supported) or by editing the stored baseline file. The package doesn’t yet automate baseline syncing, so this requires developer intervention when Psalm’s rules or messages evolve.