Constraints
- Apply
@rules/php/core-standards.mdc
- Apply
@rules/code-testing/general.mdc
- If the current project uses Laravel, also apply
@rules/laravel/laravel.mdc, @rules/laravel/architecture.mdc, @rules/laravel/filament.mdc, and @rules/laravel/livewire.mdc
- Do not generate
covers()
Use when
- Existing tests are written in PHPUnit-style syntax and should be rewritten to Pest
- You want to modernize tests without changing their intended behavior
Required approach
- Preserve test intent and coverage of the rewritten behavior
- Keep tests deterministic and non-flaky
- Prefer simple, readable Pest syntax
- Use helper methods or datasets when they clearly reduce duplication
- Avoid reflection; prefer mocks or partial mocks when readable and effective
- Avoid branching in tests; prefer separate test cases or datasets instead
Read, Map & Verify before rewriting (mandatory pre-flight)
Reading, mapping, and verifying come first; rewriting comes last. This pre-flight is blocking — do not rewrite a single line until all three steps pass, and never act on an assumption you have not confirmed by reading the code.
- Read — open and read the actual tests being rewritten and the code they exercise (the system under test, shared setup, helpers, datasets). Confirm what each test asserts by reading it, not by guessing from its name.
- Map — map the change's blast radius: every assertion and covered code path that must survive the rewrite, the shared setup/helpers to reuse, and the project's existing Pest conventions.
- Verify — run the existing tests first and confirm they pass, so you rewrite from a known-green baseline. If the original behavior or coverage is unclear, stop and clarify instead of rewriting on a wrong premise.
Only after Read, Map, and Verify are complete may the rewrite begin.
Execution
- Identify existing tests that should be rewritten to Pest syntax.
- Analyze repeated setup and assertions before rewriting.
- Rewrite tests to Pest syntax without changing covered behavior.
- Use datasets/data providers where they simplify similar test cases.
- Move broadly shared lightweight test helpers to
Pest.php when it improves clarity and reuse.
- If a Pest test needs to call a helper method defined on the test case for abstract-class scenarios, use
test()->methodName().
- Keep tests structured and easy to read, preferably with clear arrange / act / assert flow.
- Separate success and failure scenarios into distinct test cases where practical.
- Run the rewritten tests and confirm they pass consistently.
- Simplify nearby similar tests only when the cleanup is small, safe, and clearly improves maintainability.
Post-rewrite validation
- Run all rewritten tests and confirm they pass.
- Verify 100% code coverage for all rewritten test paths — if coverage tooling exists, run it.
- Discover available fixers and checkers (prefer Phing targets from
build.xml/phing.xml; fall back to Composer scripts in composer.json).
- Run available fixers on changed test files and fix any violations.
- Run available checkers/analyzers on changed test files and resolve all reported errors by rewriting the flagged code, never by adding a suppression annotation (
@rules/php/core-standards.mdc PHP Practices).
- Run a quick code review of rewritten tests against
@rules/code-testing/general.mdc and fix any findings.
Done when
- Target tests are rewritten to Pest syntax
- Rewritten tests preserve original intent and behavior
- Tests are deterministic and pass reliably
- 100% code coverage is verified for rewritten code paths
- Code style and quality checks pass (fixers and checkers ran clean)
- Test review passed with no findings
- Duplication is reduced where it meaningfully improves readability
- Shared lightweight helpers are extracted appropriately
- The rewritten tests follow project testing conventions
1---2name: rewrite-tests-pest3description: Use when rewriting existing tests to Pest syntax. Preserve behavior, follow project testing conventions, reduce duplication where helpful, and verify rewritten tests are deterministic and passing.4license: MIT5---67## Constraints8- Apply `@rules/php/core-standards.mdc`9- Apply `@rules/code-testing/general.mdc`10- If the current project uses Laravel, also apply `@rules/laravel/laravel.mdc`, `@rules/laravel/architecture.mdc`, `@rules/laravel/filament.mdc`, and `@rules/laravel/livewire.mdc`11- Do not generate `covers()`1213## Use when14- Existing tests are written in PHPUnit-style syntax and should be rewritten to Pest15- You want to modernize tests without changing their intended behavior1617## Required approach18- Preserve test intent and coverage of the rewritten behavior19- Keep tests deterministic and non-flaky20- Prefer simple, readable Pest syntax21- Use helper methods or datasets when they clearly reduce duplication22- Avoid reflection; prefer mocks or partial mocks when readable and effective23- Avoid branching in tests; prefer separate test cases or datasets instead2425## Read, Map & Verify before rewriting (mandatory pre-flight)2627Reading, mapping, and verifying come first; rewriting comes last. This pre-flight is **blocking** — do not rewrite a single line until all three steps pass, and never act on an assumption you have not confirmed by reading the code.28291. **Read** — open and read the actual tests being rewritten and the code they exercise (the system under test, shared setup, helpers, datasets). Confirm what each test asserts by reading it, not by guessing from its name.302. **Map** — map the change's blast radius: every assertion and covered code path that must survive the rewrite, the shared setup/helpers to reuse, and the project's existing Pest conventions.313. **Verify** — run the existing tests first and confirm they pass, so you rewrite from a known-green baseline. If the original behavior or coverage is unclear, stop and clarify instead of rewriting on a wrong premise.3233Only after Read, Map, and Verify are complete may the rewrite begin.3435## Execution361. Identify existing tests that should be rewritten to Pest syntax.372. Analyze repeated setup and assertions before rewriting.383. Rewrite tests to Pest syntax without changing covered behavior.394. Use datasets/data providers where they simplify similar test cases.405. Move broadly shared lightweight test helpers to `Pest.php` when it improves clarity and reuse.416. If a Pest test needs to call a helper method defined on the test case for abstract-class scenarios, use `test()->methodName()`.427. Keep tests structured and easy to read, preferably with clear arrange / act / assert flow.438. Separate success and failure scenarios into distinct test cases where practical.449. Run the rewritten tests and confirm they pass consistently.4510. Simplify nearby similar tests only when the cleanup is small, safe, and clearly improves maintainability.4647## Post-rewrite validation481. Run all rewritten tests and confirm they pass.492. Verify 100% code coverage for all rewritten test paths — if coverage tooling exists, run it.503. Discover available fixers and checkers (prefer Phing targets from `build.xml`/`phing.xml`; fall back to Composer scripts in `composer.json`).514. Run available fixers on changed test files and fix any violations.525. Run available checkers/analyzers on changed test files and resolve all reported errors **by rewriting the flagged code, never by adding a suppression annotation** (`@rules/php/core-standards.mdc` PHP Practices).536. Run a quick code review of rewritten tests against `@rules/code-testing/general.mdc` and fix any findings.5455## Done when56- Target tests are rewritten to Pest syntax57- Rewritten tests preserve original intent and behavior58- Tests are deterministic and pass reliably59- 100% code coverage is verified for rewritten code paths60- Code style and quality checks pass (fixers and checkers ran clean)61- Test review passed with no findings62- Duplication is reduced where it meaningfully improves readability63- Shared lightweight helpers are extracted appropriately64- The rewritten tests follow project testing conventions