← ClaudeAtlas

testing-laravellisted

Writes Laravel tests using PHPUnit. Use when "write tests", "add tests", "phpunit", "laravel test", "feature test", "unit test", "mock", "factory", or testing controllers, models, services, actions, jobs, artisan commands, or API endpoints.
iliaal/whetstone · ★ 20 · Testing & QA · score 81
Install: claude install-skill iliaal/whetstone
# Testing Laravel Use PHPUnit with Laravel's testing helpers. Every test file starts with `declare(strict_types=1)`. ## Test Classification - **Feature tests** (`tests/Feature/`): HTTP requests through the full stack — routes, controllers, middleware, validation, database. Use `$this->getJson()`, `$this->postJson()`, etc. - **Unit tests** (`tests/Unit/`): Isolated logic — services, actions, value objects, helpers. No HTTP, minimal database. Default to feature tests for anything touching routes, controllers, or models. Use unit tests for pure logic and action classes. ## Critical Rules - `use RefreshDatabase` trait in every test class that touches the database - Model factories for all test data — use factories instead of raw `DB::table()` inserts - One behavior per test method. Name with `test_` prefix: `test_user_can_update_own_profile` - Assert both response status AND side effects (DB state, dispatched jobs, sent notifications) - `actingAs($user)` for auth — use this instead of manually setting sessions or tokens - `postJson()` / `getJson()` for API endpoints — sets proper Accept headers and returns JSON assertions - Fake facades BEFORE the action: `Queue::fake()` then act then `Queue::assertPushed(...)` - `assertDatabaseHas` / `assertDatabaseMissing` to verify persistence — use these instead of re-querying - Resolve action classes from the container with `resolve()` so DI works; use `swap()` to inject mocks - **Tests expose bugs, not the reverse**: If a test uncover