.cursor/skills/laravel-best-practices/rules/testing.md
LazilyRefreshDatabase Over RefreshDatabaseRefreshDatabase migrates once per process and wraps each test in a rolled-back transaction. LazilyRefreshDatabase skips even that first migration if the schema is already up to date.
Incorrect: $this->assertDatabaseHas('users', ['id' => $user->id]);
Correct: $this->assertModelExists($user);
More expressive, type-safe, and fails with clearer messages.
Named states make tests self-documenting. Sequences eliminate repetitive setup.
Incorrect: User::factory()->create(['email_verified_at' => null]);
Correct: User::factory()->unverified()->create();
Exceptions::fake() to Assert Exception ReportingInstead of withoutExceptionHandling(), use Exceptions::fake() to assert the correct exception was reported while the request completes normally.
Event::fake() After Factory SetupModel factories rely on model events (e.g., creating to generate UUIDs). Calling Event::fake() before factory calls silences those events, producing broken models.
Incorrect: Event::fake(); $user = User::factory()->create();
Correct: $user = User::factory()->create(); Event::fake();
recycle() to Share Relationship Instances Across FactoriesWithout recycle(), nested factories create separate instances of the same conceptual entity.
Ticket::factory()
->recycle(Airline::factory()->create())
->create();