pestphp/pest-plugin-rector
The official Pest plugin for Rector that automates test code migrations and upgrades. Convert PHPUnit tests to Pest, upgrade Pest 1 to 2/3, and apply custom Rector rules through a single, easy-to-configure ruleset—keeping your test suite clean and modern.
$this->assert*() calls, setUp/tearDown — into Pest idioms (it(...), expect()->toBe(), beforeEach()), so the roadmap decision becomes "how much of this is automatable?" rather than "how many engineer-weeks to rewrite by hand?"setUp/tearDown to lifecycle hooks; assertion-syntax normalization; onboarding legacy apps or acquired teams onto one testing standard; reducing review overhead during a framework transition.Consider it when most of these hold:
Look elsewhere or defer when:
@depends, complex data providers, or lifecycle ordering. Expect a meaningful manual tail — budget roughly 30% manual cleanup on a real suite. The plugin is an accelerator, not an oracle, and silent semantic drift (weakened assertions, flattened data providers, reordered setUp/tearDown) is the real risk.Evaluation checklist before committing: rule coverage against your actual test idioms; supported Pest/PHP/Rector version matrix; presence of the repo's own tests; release cadence and issue responsiveness; license compatibility (MIT is permissive); contributor bus factor; and a named internal owner for pinning, upgrades, and potential fork maintenance.
To executives: This is a small, free, MIT-licensed, developer-only utility that automates a mechanical portion of test modernization. It never ships to production and adds no runtime dependency, so downside is bounded to engineering time; the upside is converting part of a multi-week manual rewrite into reviewable automated diffs. Recommendation: fund a time-boxed pilot on one representative repository, measure the automated-vs-manual fix ratio and any coverage drift, then decide the broader migration on real data rather than vendor claims or tool reputation.
To engineering leadership: It plugs into the Rector pipeline you likely already run and applies codemods that move PHPUnit-style tests toward Pest idioms. Run it in dry-run on a branch, review the generated diff, and gate merges on tests, test counts, and coverage against a green baseline. Because adoption is minimal, plan for it as a vendored, pinned tool with a named owner, and budget a small allowance for forking or authoring custom rules. Practical guardrails: scope withPaths() to explicit test directories (never the repo root — it will happily rewrite app/), order the Pest set after PHPUnit/PHP sets, verify idempotency with a second dry-run, and add a ->withSkip() for fixtures that only look like tests.
To the team doing the work: Treat the ruleset as an accelerator, not an oracle. It clears the boring majority of mechanical conversions — the 70% — but expect a manual tail around mocking, custom helpers, data providers, dependency ordering, and lifecycle semantics. Dry-run first, commit per module or directory, and review every diff even when tests pass: a green suite is not proof of correctness, because a rewritten test can pass while asserting less. Compare test and coverage counts against the PHPUnit baseline before trusting any transformation, and run a test-count assertion alongside the CI dry-run gate so a rule that deletes a test doesn't pass silently. Retire the plugin or disable the set once migration is complete — leaving an unmaintained codemod enabled in CI is a future upgrade tripwire for zero benefit.
How can I help you explore Laravel packages today?