Write tests based on actual code behavior, following practices from docs/99_2_APPENDIX_write_tests_guide.md
Usage:
bash
/write-tests "test folder creation and hierarchy management" /write-tests "test REST API endpoint permissions for different user capabilities" /write-tests "test media file assignment to folders"
MANDATORY PROCESS (SEQUENTIAL):
- •
Analyze Target Code
- •Search codebase for implementation
- •Read code and understand exact behavior
- •NO guessing - only verified behavior
- •
Find Similar Tests
- •Search tests/ for related functionality
- •Read 2-3 existing test files
- •Document patterns: helpers, assertions, structure
- •Reuse existing patterns from tests/TestsUtils/
- •
Write FIRST Test Only
- •Most important scenario (happy path or critical case)
- •Stop after writing ONE test
- •
Run and Validate FIRST Test
- •Execute:
composer phpunit --filter=test_method_name(PHP 8.0+) - •OR:
composer phpunit-74 --filter=test_method_name(PHP 7.4) - •If fails: STOP and DEBUG - see "When Tests Fail" below
- •If passes: proceed to step 5
- •Execute:
- •
Write Remaining Tests
- •Follow same structure as validated first test
- •Run full file when done
Critical Rules:
- •Follow all practices from
docs/99_2_APPENDIX_write_tests_guide.md - •WordPress capabilities: test BOTH allowed AND denied cases
- •NEVER write 20 tests at once - causes cascading errors
- •PHPUnit syntax (extends TestCase, NOT Pest)
- •Use TestsUtils helpers for common operations
When Tests Fail:
- •STOP - read error message completely
- •Search documentation (WebSearch "WordPress testing [feature]" or check WordPress Codex)
- •Find working examples in existing tests (tests/Unit/, tests/Feature/)
- •Check tests/TestsUtils/ for available helpers
- •Make ONE fix based on docs/examples
- •NEVER try random syntax without understanding error