testing-laravel

Installation
SKILL.md

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
Related skills
Installs
2
GitHub Stars
11
First Seen
Feb 22, 2026