Skip to main content
skill CX Codex

laravel-tdd · iserter — Claude Code skill: TDD with Pest PHP

A skill that walks the agent through red-green-refactor in Laravel: a failing Pest test first, minimal code to pass, then cleanup.

Install into Claude Code · Skills CLI (Vercel) All methods and platforms ↓
npx skills add iSerter/laravel-claude-agents --skill laravel-tdd -a claude-code
Open on GitHub

What laravel-tdd does

The skill sets the order of work for any Laravel feature or bugfix. A test comes first, gets run, and has to fail. Only then does the agent write the least code needed to make it pass. The loop is RED, verify RED, GREEN, verify GREEN, REFACTOR. Verification runs through php artisan test, and a single test can be filtered by name.

Inside are test patterns for Laravel: factories and RefreshDatabase for database work, actingAs for auth, assertForbidden for policies, postJson with sanctum for API routes. A checklist covers migrations, model relationships, controller actions, validation rules and database state. Refactoring waits until the test is green — extracting services, adding policies, query scopes, events.

Exceptions are left to the human: throwaway prototypes, config files, view-only changes with no logic. You need a Laravel project running Pest PHP.

What it helps with

  • write a failing test before the feature code
  • check authorization through Laravel policies
  • test an API endpoint with a sanctum token
  • keep a migration and its model in sync
  • extract complex logic into a service after green

Example prompts for the agent

  • write a test for creating a post as an authenticated user, then implement it
  • add a check that a user cannot delete someone else's post
  • cover the post creation API endpoint with tests

How to install laravel-tdd

1Skills CLI (Vercel)

npx skills add iSerter/laravel-claude-agents --skill laravel-tdd -a claude-code

2Manually: put the files in place

~/.claude/skills/laravel-tdd/SKILL.md

Copy the whole skill folder; for one project use .claude/skills/laravel-tdd/

Step by step, with commands for each platform: How to install skills in Claude Code: five ways

Questions about laravel-tdd

How do I install laravel-tdd in Claude?

Run npx skills add iSerter/laravel-claude-agents --skill laravel-tdd -a claude-code. The skill lands in ~/.claude/skills/laravel-tdd/SKILL.md.

What does laravel-tdd do?

It makes the agent write a Pest PHP test before the code, watch it fail, then write the minimal implementation and refactor afterwards.

Which platforms does the skill support?

Besides Claude there are installs for Codex, Cursor, GitHub Copilot, Gemini CLI and OpenCode — same command, different -a flag.

Source text

SKILL.md · MIT
---
name: laravel-tdd
description: Test-Driven Development specifically for Laravel applications using Pest PHP. Use when implementing any Laravel feature or bugfix - write the test first, watch it fail, write minimal code to pass.
---

# Test-Driven Development for Laravel

## Overview

Write the test first. Watch it fail. Write minimal code to pass.

This skill adapts TDD principles specifically for Laravel applications using Pest PHP, Laravel's testing features, and framework-specific patterns.

## When to Use

**Always for Laravel:**
- New features (controllers, models, services)
- Bug fixes
- API endpoints
- Database migrations and models
- Form validation
- Authorization policies
- Queue jobs
- Artisan commands
- Middleware

**Exceptions (ask your human partner):**
- Throwaway prototypes
- Configuration files
- View-only changes (no logic)

## The Laravel TDD Cycle

```
RED → Verify RED → GREEN → Verify GREEN → REFACTOR → Repeat
```

### RED - Write Failing Test

Write one minimal test showing what the Laravel feature should do.

**Feature Test Example:**
```php
<?php

use App\Models\User;
use App\Models\Post;

test('authenticated user can create post', function () {
    $user = User::factory()->create();
    
    $this->actingAs($user)
        ->post('/posts', [
            'title' => 'My First Post',
            'content' => 'Post content here',
        ])
        ->assertRedirect('/posts');
    
    expect(Post::where('title', 'My First Post')->exists())->toBeTrue();
    expect(Post::first()->user_id)->toBe($user->id);
});
```

### Verify RED - Watch It Fail

```bash
php artisan test --filter=authenticated_user_can_create_post
```

### GREEN - Minimal Laravel Code

Write simplest Laravel code to pass the test.

### Verify GREEN - Watch It Pass

```bash
php artisan test
```

### REFACTOR - Clean Up Laravel Code

After green only:
- Extract services for complex logic
- Create policies for authorization
- Add query scopes for reusability
- Use events for side effects

## Laravel-Specific Test Patterns

### Database Testing
```php
use Illuminate\Foundation\Testing\RefreshDatabase;

uses(RefreshDatabase::class);

test('creates post in database', function () {
    $user = User::factory()->create();
    
    $this->actingAs($user)
        ->post('/posts', ['title' => 'Test', 'content' => 'Content']);
    
    $this->assertDatabaseHas('posts', ['title' => 'Test']);
});
```

### Authorization Testing
```php
test('user cannot delete others posts', function () {
    $user = User::factory()->create();
    $post = Post::factory()->create();
    
    $this->actingAs($user)
        ->delete("/posts/{$post->id}")
        ->assertForbidden();
});
```

### API Testing
```php
test('creates post via API', function () {
    $user = User::factory()->create();
    
    $this->actingAs($user, 'sanctum')
        ->postJson('/api/posts', ['title' => 'API Post', 'content' => 'Content'])
        ->assertCreated();
});
```

## Verification Checklist

- [ ] Migration test passes
- [ ] Model relationships tested
- [ ] Controller actions tested
- [ ] Validation rules tested
- [ ] Authorization tested
- [ ] Database state verified
- [ ] All tests passing
- [ ] Used RefreshDatabase
- [ ] Used factories

## Remember

```
Every Laravel feature → Test exists and failed first
Otherwise → Not TDD
```

© iSerter · MIT · iSerter/laravel-claude-agents

Similar skills

Everything for Testing and QA →

laravel-tdd by other authors comes first.

From the same set2

Project sponsors

Companies that keep this analytics open
Gold sponsor

Impressions, clicks and code copies — open statistics. We keep the numbers public for the same reason NeBlask itself is public. Become a sponsor