mrpunyapal/rector-pest
Rector rules for migrating PHP tests to Pest. Automates converting PHPUnit-style tests and assertions into Pest’s fluent syntax, helping you modernize test suites quickly and consistently with minimal manual edits.
expect() calls, leveraging Pest matchers).Str:: assertions → Pest string matchers).rector/rector-pest by Spatie) with semantic-aware rules, reducing false positives/negatives.PEST_CODE_QUALITY, PEST_MIGRATION) allow granular adoption, aligning with Laravel’s preference for incremental, non-breaking changes.composer require --dev mrpunyapal/rector-pest and minimal rector.php configuration. No runtime dependencies beyond Rector/Pest.PEST_MIGRATION requires manual review), mitigating regression risks.| Risk Area | Assessment | Mitigation Strategy |
|---|---|---|
| Rule Overreach | Some rules (e.g., PEST_CHAIN) may alter test readability or intent. |
Use --dry-run to preview changes; exclude problematic files via withPaths(). |
| Version Lock-in | Rules target specific Pest versions (e.g., UP_TO_PEST_40). |
Use PestLevelSetList for upgrades; avoid mixing sets (e.g., don’t apply v3→v4 + v2→v3). |
| False Positives | Semantic rules (e.g., static callback detection) may misclassify intent. | Review docs/semantic-architecture.md; disable individual rules if needed. |
| Performance | Large test suites may slow down Rector processing. | Run in CI with --parallel; cache results if using GitHub Actions. |
| Plugin Dependencies | PEST_BROWSER requires pestphp/pest-plugin-browser. |
Document dependency as a pre-requisite; fail fast if missing. |
Adoption Scope:
Version Strategy:
UP_TO_PEST_40 be applied now, or phased with PEST_30 first?Toolchain Integration:
Maintenance:
composer require --dev) or managed centrally (e.g., via tools/ repo)?Edge Cases:
PEST_MIGRATION be used?PEST_BROWSER?PEST_MIGRATION).PEST_BROWSER).PEST_CODE_QUALITY/PEST_CHAIN).| Phase | Action | Tools/Commands |
|---|---|---|
| Assessment | Audit test suite for compatibility (e.g., Pest version, custom assertions). | composer why-not mrpunyapal/rector-pest; review tests/ structure. |
| Pilot | Apply PEST_CODE_QUALITY to a subset of tests (e.g., feature tests). |
rector process --dry-run --set PestSetList::PEST_CODE_QUALITY --paths tests/Feature |
| Validation | Verify test output, coverage, and readability. | Run tests with --verbose; check for flaky tests. |
| Full Rollout | Apply selected sets to all tests (e.g., PEST_CODE_QUALITY + PEST_CHAIN). |
Update rector.php; run in CI. |
| Upgrade | Migrate Pest versions (e.g., UP_TO_PEST_40) or PHPUnit → Pest (PEST_MIGRATION). |
Phase changes; test incrementally. |
composer.json; update if needed).UP_TO_PEST_30: Targets v2→v3.UP_TO_PEST_40: Targets v2/v3→v4.PEST_30 + PEST_40).PEST_BROWSER: Requires pestphp/pest-plugin-browser.PEST_LARAVEL: Requires illuminate/support.rector/rector to v2.4.1+ (for chaining formatting).composer require pestphp/pest --dev).composer.json:
"require-dev": {
"mrpunyapal/rector-pest": "^1.0"
}
rector.php:
use RectorPest\Set\PestSetList;
return RectorConfig::configure()
->withPaths([__DIR__.'/tests'])
->withSets([
PestSetList::PEST_CODE_QUALITY,
PestSetList::PEST_CHAIN,
]);
vendor/bin/rector process --dry-run.vendor/bin/rector process.chore: apply rector-pest code quality rules (PEST_CODE_QUALITY, PEST_CHAIN)
- name: Run Rector
run: composer run rector
mrpunyapal/rector-pest to a version (e.g., ^1.0) to avoid surprises.UP_TO_PEST_50).PEST_LARAVEL), document in rector.php:
// Custom rules
How can I help you explore Laravel packages today?