laravel-tdd

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

1|Updated Mar 18, 2026
One-click install
npx skills add https://github.com/xxih/ai-harness-zh --skill laravel-tdd-xxih
Or copy as Structured Prompt for Agent
Please help me install this Agent Skill.
Skill: laravel-tdd
Source: https://github.com/xxih/ai-harness-zh/tree/main/references/translations/everything-claude-code/docs/zh-CN/skills/laravel-tdd
Command: npx skills add https://github.com/xxih/ai-harness-zh --skill laravel-tdd-xxih

SYSTEM DOCUMENTATION & REQUIREMENTS

What problem does it solve?

Provides a practical workflow and conventions to adopt test-driven development in Laravel projects, reducing regressions and improving confidence by guiding developers to write unit, feature, and integration tests and meet a coverage target.

Core Features & Use Cases

  • Red-Green-Refactor workflow: clear cycle for writing a failing test, implementing the minimal fix, and refactoring safely.
  • Layered testing guidance: when to use unit, feature, or integration tests for services, controllers, policies, jobs, and notifications.
  • Database and isolation strategies: recommendations for RefreshDatabase, DatabaseTransactions, and DatabaseMigrations to keep tests deterministic.
  • Fakes and mocks: examples and patterns for Queue::fake, Notification::fake, Http::fake, and Event::fake to isolate external effects.
  • CI coverage enforcement: guidance to target combined unit and feature coverage of 80%+ using pcov or Xdebug in CI.

Quick Start

Write a failing Pest or PHPUnit test for the feature you want, implement the smallest change to make it pass, and run the test suite until coverage reaches the 80% target.

Frequently Asked Questions about laravel-tdd

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

FAQPage Schema
How do I enforce 80% test coverage in a Laravel CI environment?

To enforce 80% test coverage in Laravel CI, configure PHPUnit or Pest with pcov or Xdebug to collect combined unit and feature metrics and fail pipelines below the threshold.

What is the best way to isolate external effects in Laravel feature tests?

The best way to isolate external effects in Laravel feature tests is using Queue::fake, Notification::fake, Http::fake, and Event::fake to mock external interactions and ensure deterministic results.

How do I write Laravel unit and feature tests for controllers and policies?

Writing Laravel unit and feature tests for controllers and policies involves applying a Red-Green-Refactor workflow to create failing tests first, then implementing minimal code to pass them.

When should I use RefreshDatabase vs DatabaseTransactions in Laravel testing?

Use RefreshDatabase for migrations per test or DatabaseTransactions for faster isolation in Laravel testing, choosing based on whether your test suite needs a clean schema or rapid transactional rollback for deterministic state.

Can I use Pest for test-driven development in Laravel instead of PHPUnit?

Yes, you can use Pest for test-driven development in Laravel, as the workflow supports both Pest and PHPUnit for writing unit, feature, and integration tests across controllers, models, and jobs.

Why are my Laravel integration tests failing due to database state pollution?

Laravel integration tests fail from database state pollution when isolation strategies like RefreshDatabase or DatabaseTransactions are missing, causing non-deterministic data interference between test cases.