- How do I install ergebnis/rector-rules for Laravel projects?
- Run `composer require --dev ergebnis/rector-rules` in your Laravel project. The package is designed as a dev-dependency and won’t affect production. Ensure you’re using Rector 0.14+ for full compatibility.
- Which Laravel versions does this package support?
- This package works with any Laravel version but is most useful for projects using PHPUnit 9+ or Pest 2+. The rules focus on modernizing PHP code and test syntax, so they’re compatible with Laravel 8.x, 9.x, and 10.x.
- Can I use this to migrate Laravel test annotations like @test to #[Test]?
- Yes, the `ReplaceTestAttributeWithTestPrefixRector` rule automates this migration for PHPUnit 9+ test suites. It’s particularly useful for Laravel projects upgrading PHPUnit or adopting Pest 2+. Configure it in your `rector.php` file.
- Will these rules break existing Laravel code?
- No, the rules are non-breaking and structural. For example, sorting associative arrays or converting Faker property fetches to method calls won’t alter logic. Always test migrations in a staging environment or CI pipeline before merging.
- How do I configure the rules for Laravel’s test directories?
- Update your `rector.php` to include the rule and specify test directories. Example: `$config->rule(ReplaceTestAttributeWithTestPrefixRector::class)->setPaths([__DIR__.'/tests']);`. Exclude legacy tests using `.rectorignore`.
- Does this package work with Pest Framework in Laravel?
- The package primarily targets PHPUnit, but you can disable the rule for Pest files. Pest 2+ uses `it()` and `test()` syntax, so avoid running the rule on `tests/Pest.php` files. Use Pest’s native migration tools if needed.
- How do I handle custom Laravel test annotations like @uses or @runInSeparateProcess?
- The default rule focuses on standard PHPUnit attributes. To handle custom annotations, extend the rule or exclude them via `.rectorignore`. Example: `tests/Unit/*/CustomAnnotationsTest.php`.
- Can I run these rules in CI/CD for Laravel projects?
- Yes, add the rule to your CI pipeline as a pre-test step. Example GitHub Actions step: `composer rector -- --dir=tests`. Cache results to speed up large test suites. Fail builds on unmigrated attributes or log warnings for gradual adoption.
- Are there alternatives to ergebnis/rector-rules for Laravel?
- For test attribute migration, Pest provides its own tools. For general code modernization, consider `rector/rector` with its built-in rules or `nunomaduro/collision` for test-specific fixes. This package offers Laravel-specific optimizations like namespaced symbol fixes.
- How do I test that migrated tests (e.g., @test → #[Test]) behave identically?
- Run parallel test execution with PHPUnit’s `--parallel` flag to validate behavior. Compare test coverage reports before/after migration. For Pest, use its built-in migration validation tools if applicable.