{
    "url": "https://delaparra-services.nl/skills/tdd-laravel",
    "locale": "en",
    "title": "Test-Driven Development | DeLaParra Services",
    "description": "Test-driven development with red-green-refactor loop using Pest PHP. Use when user wants to build features or fix bugs using TDD, mentions \"red-green-refactor\", wants integration tests, asks for test-first development, or needs guidance on writing testable code with Pest.",
    "alternates": {
        "en": "https://delaparra-services.nl/skills/tdd-laravel",
        "nl": "https://delaparra-services.nl/nl/skills/tdd-laravel"
    },
    "formats": {
        "csv": "https://delaparra-services.nl/skills/tdd-laravel.csv",
        "md": "https://delaparra-services.nl/skills/tdd-laravel.md",
        "json": "https://delaparra-services.nl/skills/tdd-laravel.json",
        "zip": "https://delaparra-services.nl/skills/tdd-laravel.zip",
        "pdf": "https://delaparra-services.nl/skills/tdd-laravel.pdf"
    },
    "downloads": [
        {
            "url": "https://delaparra-services.nl/skills/tdd-laravel.csv",
            "encodingFormat": "text/csv",
            "name": "tdd-laravel.csv"
        },
        {
            "url": "https://delaparra-services.nl/skills/tdd-laravel.json",
            "encodingFormat": "application/json",
            "name": "tdd-laravel.json"
        },
        {
            "url": "https://delaparra-services.nl/skills/tdd-laravel.md",
            "encodingFormat": "text/markdown",
            "name": "tdd-laravel.md"
        },
        {
            "url": "https://delaparra-services.nl/skills/tdd-laravel.pdf",
            "encodingFormat": "application/pdf",
            "name": "tdd-laravel.pdf"
        },
        {
            "url": "https://delaparra-services.nl/skills/tdd-laravel.zip",
            "encodingFormat": "application/zip",
            "name": "tdd-laravel.zip"
        },
        {
            "url": "https://delaparra-services.nl/skills/tdd-laravel/download",
            "encodingFormat": "application/zip",
            "name": "tdd-laravel-files.zip"
        }
    ],
    "markdown": "# Test-Driven Development\n\n \n\nTest-driven development with red-green-refactor loop using Pest PHP. Use when user wants to build features or fix bugs using TDD, mentions \"red-green-refactor\", wants integration tests, asks for test-first development, or needs guidance on writing testable code with Pest.\n\n \n\n**Licence** MIT\n\n \n\n**Source** ceilidhboy/skills\n\n [Download zip](<https://delaparra-services.nl/skills/tdd-laravel/download>)   \n\n# Test-Driven Development\n\n \n\n## 🛑 CRITICAL: The Refactor Phase Is Mandatory\n\n \n\n**After EVERY red-green cycle, you MUST:**\n\n \n\n1. **Complete the refactor checklist** (see refactor-checklist.md) \n1. **Propose refactors to the user** with specific code examples \n1. **Get explicit user approval** before making any changes \n1. **Execute approved refactors** and verify tests still pass \n1. **Display the completed checklist** to the user before proceeding\n\n \n\n**Do NOT skip refactoring. Do NOT proceed to the next test without user approval of refactoring.**\n\n \n\nThe TDD Mantras are:\n\n \n\n- 🕉️ **RED → GREEN → REFACTOR (with user approval) → RED → GREEN → REFACTOR (with user approval) → ...** \n- 🛑 Production code may not be written or modified unless we have a RED test and are trying to make it GREEN.\n\n \n\nWhen activating the TDD skill, you MUST state the above TDD mantras to demonstrate that you understand the red-green-refactor cycle with mandatory user approval of refactoring along with requiring a red test before writing or modifying any production code.\n\n  \n\n## 🛑 CRITICAL: Pre-Action Verbalization Requirement\n\n \n\n**Before writing ANY test, you MUST verbalize the following statement:**\n\n \n\n> \"I am writing ONE test for \\[specific behavior\\]. I will not write or modify production code unless it's to make a failing red test pass (green). I will write the simplest code possible. I will present a checkpoint before proceeding to any next step.\"\n\n \n\nThis verbalization must:\n\n \n\n1. State specifically what behavior this ONE test covers \n1. Explicitly acknowledge the rule: no production code except to make a RED test GREEN \n1. Commit to writing the simplest code \n1. Commit to presenting checkpoints\n\n \n\n**You must NOT write more than one test before getting user approval to proceed.**\n\n  \n\n## Checkpoints and User Approval\n\n \n\n**⚠️ CRITICAL: You MUST use the ` question ` tool for all checkpoints. Do not output plain text options.**\n\n \n\nPresent checkpoints using the ` question ` tool with ` multiple: false `. The user clicks or presses a number to select. Never ask the user to type an answer when they can select from options.\n\n \n\nThere are **three types of checkpoints** in the TDD cycle:\n\n \n\n### 1. RED Checkpoint (After writing test)\n\n \n\n```\n━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━\nCHECKPOINT - TDD Cycle #[N] RED\n━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━\nFile:  [path]:[line]  (current test)\nTest:  [test name]\nPhase: RED\nResult: ✗ Test fails (as expected)\n━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━\n```\n\n \n\n**Options after RED:**\n\n \n\n1. **\"Write the simplest code to make the test pass\"** - Proceed to GREEN phase (write minimal code only) \n1. **\"Stop and discuss\"** - User wants to review/refine the test before proceeding \n1. **\"Type your own answer\"** - User has custom feedback\n\n \n\n### 2. GREEN Checkpoint (After test passes)\n\n \n\n```\n━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━\nCHECKPOINT - TDD Cycle #[N] GREEN\n━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━\nFile:  [path]:[line]  (current test)\nTest:  [test name]\nPhase: GREEN\nCode:  [one-line code summary]\nResult: ✓ Test passes\n━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━\n```\n\n \n\n**Options after GREEN:**\n\n \n\n1. **\"Next test\"** - Proceed to RED phase for next test \n1. **\"Refactor\"** - Enter REFACTOR phase \n1. **\"Stop and discuss\"** - Pause to discuss\n\n \n\n### 3. REFACTOR Checkpoint (After refactor)\n\n \n\n```\n━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━\nCHECKPOINT - TDD Cycle #[N] REFACTOR\n━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━\nFile:  [path]:[line]  (current test)\nPhase: REFACTOR\nChanges: [summary of refactor]\nResult: ✓ Tests still pass\n━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━\n```\n\n \n\n**Options after REFACTOR:**\n\n \n\n1. **\"Continue refactoring\"** - More refactoring, stay in REFACTOR phase \n1. **\"Next test\"** - Proceed to RED phase for next test \n1. **\"Stop and discuss\"** - Pause to discuss\n\n  \n\n## 🛑 ABSOLUTE RULE: Stop Points After Every Phase\n\n \n\n**After completing RED, GREEN, or REFACTOR phase, you MUST stop and use the ` question ` tool to get user approval before any tool use.**\n\n \n\n**Do NOT:**\n\n \n\n- Write any code \n- Run any commands \n- Make any changes \n- Proceed to next phase\n\n \n\n**until the user has clicked an option and you have received their response.**\n\n \n\n**Do NOT:**\n\n \n\n- Write any code \n- Run any commands \n- Make any changes \n- Proceed to next phase\n\n \n\n**until the user has clicked an option and you have received their response.**\n\n  \n\n## Quick Start\n\n \n\nTDD follows the **red-green-refactor** cycle:\n\n \n\n1. **RED**: Write a test that fails \n1. **GREEN**: Write the **simplest code** that passes (not optimal code) \n1. **REFACTOR**: Clean up, extract duplication, apply patterns (with user approval) \n1. **Repeat** for next behavior\n\n \n\n## Triangulation: How Code Evolves to Perfection\n\n \n\n**The critical insight:** Don't try to write perfect code in the GREEN phase. Write the simplest thing that works, then let multiple tests guide you to the best solution.\n\n \n\n### The Process\n\n \n\n1. **First test (degenerate):** Write the simplest test. Make it pass with hardcoded values if needed. \n1. **Second test (different case):** Now you can't hardcode - write actual logic (still simple, may be oversimplified). \n1. **Third test (more complex):** Oversimplified logic breaks. Now you write more general, correct code. \n1. **Refactor after each test:** With multiple tests as a safety net, improve code quality and apply SOLID principles.\n\n \n\n### Why This Works\n\n \n\nEach new test **triangulates** you toward the best solution. The code naturally converges on the cleanest, most general implementation because:\n\n \n\n- You're always writing the simplest thing that works \n- Multiple tests prevent overengineering (you only add complexity when forced by a failing test) \n- Refactoring is safe (tests catch regressions)\n\n \n\n**Without TDD:** You anticipate all cases upfront and write overly complex code. **With TDD:** Tests guide you to the right level of complexity naturally.\n\n \n\n## Core Principles\n\n \n\n- **Tests verify behavior, not implementation** — See philosophy.md \n- **Vertical slices, not horizontal** — See anti-patterns.md \n- **One test at a time** — Each test responds to what you learned from the previous cycle \n- **Minimal code to pass** — Don't anticipate future tests \n- **Deep modules with real dependencies** — Test through real interfaces, not mocks of internal parts — See deep-modules.md \n- **Integration-style testing** — Exercise real code paths through public APIs, not implementation details\n\n \n\n## ⚠️ CRITICAL: Feature Tests Required for Laravel Code\n\n \n\n**Any test that uses Eloquent models, facades, or the Laravel application container MUST be a Feature test, not a Unit test.**\n\n \n\nUnit tests do not load the Laravel application. If your test uses ` Model::factory() `, ` app() `, ` Mail:: `, ` Storage:: `, or any other Laravel feature, it must be in ` tests/Feature/ `, not ` tests/Unit/ `.\n\n \n\n## Degenerate Tests: Your Safety Net\n\n \n\n**Always write the degenerate (negative) test first** before the positive test.\n\n \n\n### Why?\n\n \n\nThe degenerate test becomes your **safety net** that catches accidental behavior. Once it's GREEN, it will immediately go RED if you accidentally implement the behavior you're trying to avoid.\n\n \n\n### Example\n\n \n\nWhen implementing \"fire event when PDF fields change\":\n\n \n\n1. **First (degenerate)**: Write test \"event does NOT fire when non-PDF fields change\" → GREEN (no code yet) \n1. **Second (positive)**: Write test \"event fires when PDF fields change\" → RED (event not implemented) \n1. **Implement**: Fire event (simplest thing) → First test goes RED (oops, firing for all changes) \n1. **Refine**: Only fire for PDF-relevant fields → Both tests GREEN\n\n \n\nThe degenerate test caught your mistake in step 3 and guided you to the correct implementation.\n\n \n\n## Default Testing Pattern: Deep Modules with Real Dependencies\n\n \n\nThis project's default approach is **integration-style testing with real dependencies**:\n\n \n\n- **Create real data** using factories (e.g., ` Property::factory()->create() `) \n- **Use real dependencies** - Inject actual actions and services, not mocks \n- **Test observable behavior** - Verify what the system does through its public interface \n- **Avoid mocking internal collaborators** - Only mock at system boundaries (external APIs, time, randomness)\n\n \n\n**Why this approach?**\n\n \n\n- Catches real integration issues that mocks would hide \n- Tests are simpler to write (no complex mock setup) \n- Tests survive refactoring because they test behavior, not implementation \n- More confidence in the code working end-to-end\n\n \n\n**When to mock:**\n\n \n\n- External APIs (payment gateways, email services, etc.) \n- Time/randomness (use ` now() `, ` fake() `) \n- File system operations (use ` Storage::fake() `) \n- Never mock your own classes or internal collaborators\n\n \n\nSee deep-modules.md and mocking.md for detailed guidance.\n\n \n\n## The Workflow\n\n \n\nSee workflow.md for detailed step-by-step guidance on:\n\n \n\n- Planning before you code \n- Writing tracer bullets \n- The incremental loop \n- When and how to refactor\n\n \n\n## Important: Single Task Responsibility\n\n \n\n**See single-task-responsibility skill.**\n\n \n\nWhile implementing a task, if you discover you're addressing **multiple distinct responsibilities**, STOP immediately and consult the user. Each task should have a single, well-defined responsibility.\n\n \n\n## Refactor Checklist\n\n \n\n**See refactor-checklist.md for the mandatory checklist you must complete after every GREEN phase.**\n\n \n\nYou MUST display the completed checklist to the user with all items marked complete before proceeding to the next task.\n\n \n\n## Reference Materials\n\n \n\n- tests.md — Testing examples and patterns \n- mocking.md — Mocking guidelines \n- deep-modules.md — Designing deep modules \n- interface-design.md — Designing for testability \n- refactoring.md — Refactoring patterns\n\n \n\n## Files\n\n \n\n- ` LICENSE ` \n- ` SKILL.md ` \n- ` SOURCE.md ` \n- ` anti-patterns.md ` \n- ` deep-modules.md ` \n- ` interface-design.md ` \n- ` mocking.md ` \n- ` philosophy.md ` \n- ` refactor-checklist.md ` \n- ` refactoring.md ` \n- ` tests.md ` \n- ` workflow.md `\n\n \n\n## Related terms\n\n \n\n- [Unit test](<https://delaparra-services.nl/knowledge-hub/unit-test>)\n\n \n\n[Installing an agent skill in Claude Code, Codex, Cursor and Copilot](<https://delaparra-services.nl/manuals/een-skill-installeren-in-je-ai-assistent>)\n\n[HTML version](https://delaparra-services.nl/skills/tdd-laravel)\n",
    "structured_data": {
        "@context": "https://schema.org",
        "@graph": [
            {
                "@type": "Organization",
                "@id": "https://delaparra-services.nl/#practice",
                "logo": "https://delaparra-services.nl/logo.png",
                "name": "DeLaParra Services",
                "legalName": "DeLaParra Services",
                "url": "https://delaparra-services.nl/",
                "description": "Bespoke software, web applications and mobile apps, developed in Laravel by a single developer in Groningen. Fixed price agreed in advance, full source code provided upon delivery.",
                "email": "info@delaparra-services.nl",
                "address": {
                    "@type": "PostalAddress",
                    "addressLocality": "Groningen",
                    "addressRegion": "Groningen",
                    "addressCountry": "NL"
                },
                "areaServed": "Groningen, the Netherlands",
                "knowsLanguage": [
                    "en",
                    "nl"
                ],
                "knowsAbout": [
                    "Web design and development",
                    "App development",
                    "Custom software and web applications",
                    "OpenSpec",
                    "AI code review",
                    "Your own coding agent"
                ],
                "founder": {
                    "@id": "https://delaparra-services.nl/#person"
                }
            },
            {
                "@type": "WebPage",
                "@id": "https://delaparra-services.nl/skills/tdd-laravel#webpage",
                "url": "https://delaparra-services.nl/skills/tdd-laravel",
                "name": "Test-Driven Development | DeLaParra Services",
                "description": "Test-driven development with red-green-refactor loop using Pest PHP. Use when user wants to build features or fix bugs using TDD, mentions \"red-green-refactor\", wants integration tests, asks for test-first development, or needs guidance on writing testable code with Pest.",
                "isPartOf": {
                    "@id": "https://delaparra-services.nl/#website"
                },
                "about": {
                    "@id": "https://delaparra-services.nl/#practice"
                },
                "inLanguage": "en",
                "breadcrumb": {
                    "@id": "https://delaparra-services.nl/skills/tdd-laravel#breadcrumb"
                }
            },
            {
                "@type": "BreadcrumbList",
                "@id": "https://delaparra-services.nl/skills/tdd-laravel#breadcrumb",
                "itemListElement": [
                    {
                        "@type": "ListItem",
                        "position": 1,
                        "name": "Home",
                        "item": "https://delaparra-services.nl/"
                    },
                    {
                        "@type": "ListItem",
                        "position": 2,
                        "name": "Test-Driven Development"
                    }
                ]
            },
            {
                "@type": "Person",
                "@id": "https://delaparra-services.nl/#person",
                "name": "Reinier de la Parra",
                "url": "https://delaparra-services.nl/about"
            },
            {
                "@type": "SoftwareSourceCode",
                "@id": "https://delaparra-services.nl/skills/tdd-laravel#skill",
                "url": "https://delaparra-services.nl/skills/tdd-laravel",
                "name": "Test-Driven Development",
                "description": "Test-driven development with red-green-refactor loop using Pest PHP. Use when user wants to build features or fix bugs using TDD, mentions \"red-green-refactor\", wants integration tests, asks for test-first development, or needs guidance on writing testable code with Pest.",
                "inLanguage": "en",
                "license": "https://spdx.org/licenses/MIT.html",
                "subjectOf": {
                    "@id": "https://delaparra-services.nl/skills/tdd-laravel#dataset"
                }
            },
            {
                "@type": "Dataset",
                "@id": "https://delaparra-services.nl/skills/tdd-laravel#dataset",
                "name": "Test-Driven Development",
                "description": "Test-driven development with red-green-refactor loop using Pest PHP. Use when user wants to build features or fix bugs using TDD, mentions \"red-green-refactor\", wants integration tests, asks for test-first development, or needs guidance on writing testable code with Pest.",
                "url": "https://delaparra-services.nl/skills/tdd-laravel",
                "identifier": "https://delaparra-services.nl/skills/tdd-laravel#dataset",
                "about": {
                    "@id": "https://delaparra-services.nl/skills/tdd-laravel#skill"
                },
                "creditText": "ceilidhboy/skills",
                "publisher": {
                    "@id": "https://delaparra-services.nl/#practice"
                },
                "license": "https://spdx.org/licenses/MIT.html",
                "isAccessibleForFree": true,
                "inLanguage": "en",
                "dateModified": "2026-11-28T14:00:12+00:00",
                "isPartOf": {
                    "@type": "Dataset",
                    "@id": "https://delaparra-services.nl/knowledge-hub#skills",
                    "name": "Skills for AI coding assistants",
                    "url": "https://delaparra-services.nl/knowledge-hub"
                },
                "includedInDataCatalog": {
                    "@type": "DataCatalog",
                    "@id": "https://delaparra-services.nl/knowledge-hub#catalog",
                    "name": "Knowledge hub data catalog",
                    "url": "https://delaparra-services.nl/knowledge-hub"
                },
                "distribution": [
                    {
                        "@type": "DataDownload",
                        "name": "tdd-laravel.csv",
                        "encodingFormat": "text/csv",
                        "contentUrl": "https://delaparra-services.nl/skills/tdd-laravel.csv",
                        "inLanguage": "en",
                        "dateModified": "2026-11-28T14:00:12+00:00",
                        "license": "https://spdx.org/licenses/MIT.html"
                    },
                    {
                        "@type": "DataDownload",
                        "name": "tdd-laravel.json",
                        "encodingFormat": "application/json",
                        "contentUrl": "https://delaparra-services.nl/skills/tdd-laravel.json",
                        "inLanguage": "en",
                        "dateModified": "2026-11-28T14:00:12+00:00",
                        "license": "https://spdx.org/licenses/MIT.html"
                    },
                    {
                        "@type": "DataDownload",
                        "name": "tdd-laravel.md",
                        "encodingFormat": "text/markdown",
                        "contentUrl": "https://delaparra-services.nl/skills/tdd-laravel.md",
                        "inLanguage": "en",
                        "dateModified": "2026-11-28T14:00:12+00:00",
                        "license": "https://spdx.org/licenses/MIT.html"
                    },
                    {
                        "@type": "DataDownload",
                        "name": "tdd-laravel.pdf",
                        "encodingFormat": "application/pdf",
                        "contentUrl": "https://delaparra-services.nl/skills/tdd-laravel.pdf",
                        "inLanguage": "en",
                        "dateModified": "2026-11-28T14:00:12+00:00",
                        "license": "https://spdx.org/licenses/MIT.html"
                    },
                    {
                        "@type": "DataDownload",
                        "name": "tdd-laravel.zip",
                        "encodingFormat": "application/zip",
                        "contentUrl": "https://delaparra-services.nl/skills/tdd-laravel.zip",
                        "inLanguage": "en",
                        "dateModified": "2026-11-28T14:00:12+00:00",
                        "license": "https://spdx.org/licenses/MIT.html"
                    },
                    {
                        "@type": "DataDownload",
                        "name": "tdd-laravel-files.zip",
                        "encodingFormat": "application/zip",
                        "contentUrl": "https://delaparra-services.nl/skills/tdd-laravel/download",
                        "inLanguage": "en",
                        "dateModified": "2026-11-28T14:00:12+00:00",
                        "license": "https://spdx.org/licenses/MIT.html"
                    }
                ]
            }
        ]
    }
}