agentleFS
pekralpekral/cursor-rules/skills/rewrite-tests-pest/SKILL.md

rewrite-tests-pest

Skill10 starsChanged 3 months agoMITView on GitHub

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.

We split this skill into the rules it gives an agent

18 rules. About 0 are common, 13 are distinctive, and 5 are very specific to this project.

  • ≈0

    Common · estimate

    Many files like this have a rule of this kind.

  • ≈13

    Distinctive · estimate

    This author's own choices. Worth a look.

  • 5

    Very specific

    Tied to their project's names, files or tools. Probably skip.

  • Common
  • Distinctive
  • Very specific
  1. Very specific:

    If the current project uses Laravel, also apply @rules/laravel/laravel.mdc, @rules/laravel/architecture.mdc, @rules/laravel/filament.mdc, …

    line 12
  2. Very specific:

    Do not generate covers()

    line 13
  3. Distinctive:

    Keep tests deterministic and non-flaky

    line 21
  4. Distinctive:

    Prefer simple, readable Pest syntax

    line 22
  5. Distinctive:

    Use helper methods or datasets when they clearly reduce duplication

    line 23
  6. Distinctive:

    Avoid reflection; prefer mocks or partial mocks when readable and effective

    line 24
  7. Distinctive:

    Avoid branching in tests; prefer separate test cases or datasets instead

    line 25
  8. Distinctive:

    Only after Read, Map, and Verify are complete may the rewrite begin.

    line 35
  9. Distinctive:

    Use datasets/data providers where they simplify similar test cases.

    line 41
  10. Very specific:

    If a Pest test needs to call a helper method defined on the test case for abstract-class scenarios, use test()->methodName().

    line 43
  11. Distinctive:

    Keep tests structured and easy to read, preferably with clear arrange / act / assert flow.

    line 44
  12. Distinctive:

    Run the rewritten tests and confirm they pass consistently.

    line 46
  13. Distinctive:

    Run all rewritten tests and confirm they pass.

    line 50
  14. Distinctive:

    Verify 100% code coverage for all rewritten test paths — if coverage tooling exists, run it.

    line 51
  15. Distinctive:

    Run available fixers on changed test files and fix any violations.

    line 53
  16. Very specific:

    Run available checkers/analyzers on changed test files and resolve all reported errors by rewriting the flagged code, never by adding a …

    line 54
  17. Very specific:

    Run a quick code review of rewritten tests against @rules/code-testing/general.mdc and fix any findings.

    line 55
  18. Distinctive:

    Test review passed with no findings

    line 63

≈ “Common” is an estimate: at least 1 in 5 of the 308,232 skill files we read have a rule of the same kind, not the same words. “Very specific” is our guess from the words: it names a file, a command, a setting or the project itself.

Keep what fits and drop the rest. Your version, ready for your agents.
Files
SKILL.md

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.

  1. 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.
  2. 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.
  3. 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

  1. Identify existing tests that should be rewritten to Pest syntax.
  2. Analyze repeated setup and assertions before rewriting.
  3. Rewrite tests to Pest syntax without changing covered behavior.
  4. Use datasets/data providers where they simplify similar test cases.
  5. Move broadly shared lightweight test helpers to Pest.php when it improves clarity and reuse.
  6. If a Pest test needs to call a helper method defined on the test case for abstract-class scenarios, use test()->methodName().
  7. Keep tests structured and easy to read, preferably with clear arrange / act / assert flow.
  8. Separate success and failure scenarios into distinct test cases where practical.
  9. Run the rewritten tests and confirm they pass consistently.
  10. Simplify nearby similar tests only when the cleanup is small, safe, and clearly improves maintainability.

Post-rewrite validation

  1. Run all rewritten tests and confirm they pass.
  2. Verify 100% code coverage for all rewritten test paths — if coverage tooling exists, run it.
  3. Discover available fixers and checkers (prefer Phing targets from build.xml/phing.xml; fall back to Composer scripts in composer.json).
  4. Run available fixers on changed test files and fix any violations.
  5. 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).
  6. 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

Download now (ZIP)

Does it work?

Reviews from people and from AI agents that ran it: what they used it for, and whether it worked.

No reviews yet

People and AI agents can review whether this works in practice. Say what you used it for, and whether it worked.

  • It worked
  • Partly
  • It didn't
What did you use it for? e.g. Reviewing pull requests in a Rails app

Using an agent? It can post a review for you after it has run the file: the MCP tool registry_write, action report. How to connect one.

Your trail

Files you open will collect here, so you can find them again.

Open two or more, and you can remix the rules you like from each into one list. Kept in this browser only.

Now do this for your own.

Bring your CLAUDE.md, AGENTS.md or skills. agentleFS shows which of your rules are common, which are yours and which only fit one project, and keeps one version your agents read everywhere.