laravel-tdd

Guides test-driven development for Laravel applications using PHPUnit and Pest.

Updated Apr 18, 2026
One-click install
npx skills add https://github.com/JohnRebellion/.claude-public --skill laravel-tdd-johnrebellion
Or copy as Structured Prompt for Agent▼
Please help me install this Agent Skill.
Skill: laravel-tdd
Source: https://github.com/JohnRebellion/.claude-public/tree/main/claude/skills/laravel-tdd
Command: npx skills add https://github.com/JohnRebellion/.claude-public --skill laravel-tdd-johnrebellion

SYSTEM DOCUMENTATION & REQUIREMENTS

What problem does it solve? Writing reliable Laravel tests requires choosing the right test layer, database strategy, and framework, and developers often struggle with inconsistent coverage, slow database tests, and untested side effects like jobs, mail, and notifications. ## Core Features & Use Cases - Red-Green-Refactor Workflow: Enforces a disciplined TDD cycle with unit, feature, and integration test layers for models, endpoints, policies, and jobs. - Database Testing Strategies: Selects between RefreshDatabase, DatabaseTransactions, and DatabaseMigrations, with in-memory SQLite configuration for fast test runs. - Fakes and Isolation: Uses Bus, Queue, Mail, Notification, Event, and Http fakes plus Sanctum auth helpers to test side effects without external services. - Use Case: When adding a new API endpoint, write a failing Pest feature test with factories and RefreshDatabase, implement the minimal controller logic, then assert the JSON structure and database state while faking queued notifications. ## Quick Start Write a failing Pest feature test for my new Laravel endpoint using factories and RefreshDatabase, then guide me through making it pass.

Frequently Asked Questions about laravel-tdd

High-intent search queries and answers about installing and using this skill.

FAQPage Schema
How do I write feature tests for Laravel API endpoints?▼

Use PHPUnit or Pest with RefreshDatabase, create test data via factories, authenticate with actingAs or Sanctum::actingAs, then call postJson or getJson and assert the status code, JSON structure, and database state with assertDatabaseHas.

Should I use Pest or PHPUnit for Laravel testing?▼

Default to Pest for new tests because of its concise syntax and Laravel plugin helpers. Use PHPUnit only when the project already standardizes on it or requires PHPUnit-specific tooling.

RefreshDatabase vs DatabaseTransactions in Laravel tests?▼

RefreshDatabase is the default: it migrates once per run and wraps each test in a transaction, or re-migrates per test for in-memory SQLite. Use DatabaseTransactions only when the schema is already migrated and you just need per-test rollback.

How do I test queued jobs and notifications in Laravel?▼

Use Queue::fake() with Queue::assertPushed for jobs and Notification::fake() with Notification::assertSentTo for notifications. Fakes prevent real dispatching so tests stay fast and isolated from external services.

How do I make Laravel tests run faster?▼

Configure phpunit.xml with DB_CONNECTION=sqlite and DB_DATABASE=:memory: so tests run against an in-memory database. Keep a separate test environment to avoid touching development or production data.