laravel-tdd

Guides test-driven development of Laravel features using Pest PHP tests.

1|Updated Jan 10, 2024
One-click install
npx skills add https://github.com/noemdb/cfla --skill laravel-tdd-noemdb
Or copy as Structured Prompt for Agent▼
Please help me install this Agent Skill.
Skill: laravel-tdd
Source: https://github.com/noemdb/cfla/tree/main/.claude/skills/laravel-tdd
Command: npx skills add https://github.com/noemdb/cfla --skill laravel-tdd-noemdb

SYSTEM DOCUMENTATION & REQUIREMENTS

What problem does it solve? It enforces a disciplined red-green-refactor workflow for Laravel development, ensuring every feature, bugfix, and API endpoint is backed by a failing test before any implementation code is written. ## Core Features & Use Cases - Laravel TDD Cycle: Walks through writing a failing Pest test, verifying the failure, writing minimal code to pass, and refactoring safely. - Framework-Specific Test Patterns: Provides ready-to-use Pest examples for database testing with RefreshDatabase, authorization checks, and API endpoint testing with Sanctum. - Verification Checklist: Ensures migrations, model relationships, validation rules, and authorization are all covered by tests. - Use Case: When adding a new endpoint like creating posts, write the feature test first, watch it fail, then implement the controller and model logic until the suite passes. ## Quick Start Ask the assistant to implement a new Laravel feature using test-driven development with Pest, starting from a failing test.

Frequently Asked Questions about laravel-tdd

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

FAQPage Schema
How do I do test-driven development in Laravel with Pest?▼

Write one minimal Pest test describing the feature, run php artisan test with a filter to watch it fail, then write the simplest Laravel code to make it pass. After green, refactor by extracting services, policies, or query scopes.

How to test Laravel API endpoints with authentication?▼

Use actingAs with the sanctum guard and postJson to send authenticated API requests in Pest tests. Assert the expected HTTP status such as assertCreated and verify database state afterward.

Does Laravel testing support database rollback between tests?▼

Yes, apply the RefreshDatabase trait via uses(RefreshDatabase::class) in Pest to migrate a fresh database for each test. Combine with model factories to seed required records like users or posts.

When should I skip TDD in a Laravel project?▼

TDD can be skipped for throwaway prototypes, configuration files, and view-only changes with no logic, but you should confirm with your team first. All features, bug fixes, and endpoints should follow the test-first cycle.

Why verify a test fails before writing Laravel implementation code?▼

Watching the test fail confirms it actually exercises the missing behavior rather than passing for the wrong reason. This red step is what distinguishes genuine TDD from writing tests after the fact.