# Testing Standards

## Rule

No task is complete until all tests pass. If no tests exist for code you wrote — write them first.

## Standards

- **PHPUnit Feature tests** for every new controller action → `tests/Feature/`
- **Unit tests** for complex service methods → `tests/Unit/`
- **Multi-tenancy:** always write a test that a user cannot access another tenant's data (see `tests/Feature/Franchise/` for patterns)
- **Naming:** `test_<module>_<behavior>` — e.g., `test_reservation_blocks_overlapping_dates`
- **Database:** SQLite in-memory (configured in `phpunit.xml`) — never use the dev MySQL DB in tests

## Commands

```bash
php artisan test                              # All tests
php artisan test --filter=ReservationTest     # Specific class
php artisan test --coverage                   # With coverage report
npm run lint                                  # ESLint check
npm run types                                 # TypeScript type check (tsc --noEmit)
```

## Bug Fix Protocol (Law 5)

1. Read the error output — extract exact message, stack trace, failing test name.
2. Identify the failing file and line number.
3. Form a hypothesis before touching code.
4. Apply the minimal fix for the root cause.
5. Re-run the full suite (not just the failing test).
6. After 3 failed attempts: stop, document in `errors.md`, escalate to user.

**Never:** skip a test, comment it out, or mark it `skip` without explicit user approval.
