{
    "url": "https://delaparra-services.nl/skills/laravel-testing",
    "locale": "en",
    "title": "Laravel 13 Testing — Pest PHP 4 & PHPUnit 12 | DeLaParra Services",
    "description": "Laravel 13 testing with Pest PHP 4 or PHPUnit 12. Use when writing feature tests, unit tests, or any test code in a Laravel application. Triggers on tasks involving HTTP tests, model factories, database assertions, mocking facades, authentication testing, or test organisation patterns.",
    "alternates": {
        "en": "https://delaparra-services.nl/skills/laravel-testing",
        "nl": "https://delaparra-services.nl/nl/skills/laravel-testing"
    },
    "formats": {
        "csv": "https://delaparra-services.nl/skills/laravel-testing.csv",
        "md": "https://delaparra-services.nl/skills/laravel-testing.md",
        "json": "https://delaparra-services.nl/skills/laravel-testing.json",
        "zip": "https://delaparra-services.nl/skills/laravel-testing.zip",
        "pdf": "https://delaparra-services.nl/skills/laravel-testing.pdf"
    },
    "downloads": [
        {
            "url": "https://delaparra-services.nl/skills/laravel-testing.csv",
            "encodingFormat": "text/csv",
            "name": "laravel-testing.csv"
        },
        {
            "url": "https://delaparra-services.nl/skills/laravel-testing.json",
            "encodingFormat": "application/json",
            "name": "laravel-testing.json"
        },
        {
            "url": "https://delaparra-services.nl/skills/laravel-testing.md",
            "encodingFormat": "text/markdown",
            "name": "laravel-testing.md"
        },
        {
            "url": "https://delaparra-services.nl/skills/laravel-testing.pdf",
            "encodingFormat": "application/pdf",
            "name": "laravel-testing.pdf"
        },
        {
            "url": "https://delaparra-services.nl/skills/laravel-testing.zip",
            "encodingFormat": "application/zip",
            "name": "laravel-testing.zip"
        },
        {
            "url": "https://delaparra-services.nl/skills/laravel-testing/download",
            "encodingFormat": "application/zip",
            "name": "laravel-testing-files.zip"
        }
    ],
    "markdown": "# Laravel 13 Testing — Pest PHP 4 & PHPUnit 12\n\n \n\nLaravel 13 testing with Pest PHP 4 or PHPUnit 12. Use when writing feature tests, unit tests, or any test code in a Laravel application. Triggers on tasks involving HTTP tests, model factories, database assertions, mocking facades, authentication testing, or test organisation patterns.\n\n \n\n**Licence** MIT\n\n \n\n**Source** AsyrafHussin/agent-skills\n\n [Download zip](<https://delaparra-services.nl/skills/laravel-testing/download>)   \n\n# Laravel 13 Testing — Pest PHP 4 & PHPUnit 12\n\n \n\n> **Supports both Pest PHP 4 and PHPUnit 12.** See Framework Detection below.\n\n \n\n**PHPUnit version note:** Laravel 13 ships with ` phpunit/phpunit: ^12.5.12 ` in its default ` composer.json `. All patterns in this skill are compatible with PHPUnit 11, 12, and 13.\n\n \n\nComprehensive testing guide for Laravel 13 applications. Contains 24 rules across 6 categories for writing fast, readable, and reliable tests. Supports both **Pest PHP 4** and **PHPUnit 12** (Laravel 13 default).\n\n \n\n## Framework Detection\n\n \n\n**Before writing or reviewing any test code, detect which testing framework the project uses:**\n\n \n\n### Step 1 — Check composer.json\n\n \n\n```\n# Look for these in require-dev:\n# \"pestphp/pest\" → Pest\n# \"phpunit/phpunit\" (without pest) → PHPUnit\n```\n\n \n\n- If ` pestphp/pest ` is present → **use Pest syntax** \n- If only ` phpunit/phpunit ` is present → **use PHPUnit syntax** \n- If both are present → **Pest takes priority** (Pest runs on top of PHPUnit)\n\n \n\n### Step 2 — Check for tests/Pest.php\n\n \n\n- If ` tests/Pest.php ` exists → **Pest is configured**, use Pest syntax\n\n \n\n### Step 3 — If still unclear, ask the user\n\n \n\n> \"I couldn't detect the testing framework. Does this project use **Pest PHP** or **PHPUnit**?\"\n\n  \n\n## Syntax Reference\n\n \n\n### Test Declaration\n\n     Pest PHPUnit     Test function ` test('...', fn() => ...) ` ` public function test_...(): void `   Readable name ` it('...', fn() => ...) ` ` #[Test] public function it_...() `   Grouping ` describe('...', fn() => ...) ` Test class name / nested classes   Trait application ` uses(RefreshDatabase::class) ` ` use RefreshDatabase; ` inside class   Before each ` beforeEach(fn() => ...) ` ` protected function setUp(): void `   After each ` afterEach(fn() => ...) ` ` protected function tearDown(): void `   Parameterised ` ->with([...]) ` ` #[DataProvider] ` attribute   Global setup ` uses(...)->in('Feature') ` in ` Pest.php ` Base ` TestCase ` class    \n\n### Core assertions (identical in both frameworks)\n\n \n\n` assertStatus `, ` assertJson `, ` assertJsonPath `, ` assertDatabaseHas `, ` assertModelExists `, ` actingAs `, ` Mail::fake() `, ` Queue::fake() `, ` Event::fake() `, ` Notification::fake() `, ` Storage::fake() ` — all work the same in Pest and PHPUnit.\n\n  \n\n## When to Apply\n\n \n\nReference these guidelines when:\n\n \n\n- Writing feature or unit tests for Laravel \n- Testing HTTP endpoints and API responses \n- Creating factories and test data \n- Asserting database state after operations \n- Faking Mail, Queue, Notification, or Event facades \n- Testing authenticated routes and API tokens \n- Organising tests with describe blocks, datasets, or test classes\n\n \n\n## Rule Categories by Priority\n\n    Priority Category Impact Prefix     1 HTTP & Feature Tests CRITICAL ` http- `   2 Model Factories CRITICAL ` factory- `   3 Database Assertions HIGH ` db- `   4 Faking Services HIGH ` fake- `   5 Authentication Testing HIGH ` auth- `   6 Test Organisation Patterns MEDIUM ` pest- `    \n\n## Quick Reference\n\n \n\n### 1. HTTP & Feature Tests (CRITICAL)\n\n \n\n- ` http-test-structure ` - Arrange/Act/Assert with factories — Pest + PHPUnit examples \n- ` http-assert-response ` - assertStatus, assertJson, assertRedirect, assertJsonMissing \n- ` http-assert-json-fluent ` - Fluent assertJson with AssertableJson closure \n- ` http-refresh-database ` - RefreshDatabase vs DatabaseTransactions — when to use each\n\n \n\n### 2. Model Factories (CRITICAL)\n\n \n\n- ` factory-define ` - Define factories with typed fake data and PHP 8.3 syntax \n- ` factory-states ` - Factory states for distinct test scenarios \n- ` factory-sequences ` - sequence() for varied data across multiple records \n- ` factory-relationships ` - has(), for(), recycle(), afterCreating()\n\n \n\n### 3. Database Assertions (HIGH)\n\n \n\n- ` db-assert-has ` - assertDatabaseHas, assertModelExists for presence checks \n- ` db-assert-missing ` - assertDatabaseMissing, assertModelMissing for deletion \n- ` db-assert-soft-deletes ` - assertSoftDeleted, trashed() factory state\n\n \n\n### 4. Faking Services (HIGH)\n\n \n\n- ` fake-mail ` - Mail::fake(), assertSent vs assertQueued, assertNothingSent \n- ` fake-queue ` - Queue::fake(), assertPushed, assertPushedOn \n- ` fake-notification ` - Notification::fake(), assertSentTo, assertCount \n- ` fake-event ` - Event::fake(), assertDispatched, assertNotDispatched \n- ` fake-storage ` - Storage::fake(), UploadedFile::fake(), assertExists \n- ` fake-ai-agent ` - Agent::fake(), assertPrompted, preventStrayPrompts (Laravel 13+) \n- ` fake-ai-media ` - Image::fake(), Audio::fake(), Transcription::fake() (Laravel 13+) \n- ` fake-ai-data ` - Embeddings::fake(), Reranking::fake(), Files::fake(), Stores::fake() (Laravel 13+)\n\n \n\n### 5. Authentication Testing (HIGH)\n\n \n\n- ` auth-acting-as ` - actingAs() for session/web authenticated tests \n- ` auth-sanctum ` - Sanctum::actingAs() for API token authentication\n\n \n\n### 6. Test Organisation Patterns (MEDIUM)\n\n \n\n- ` pest-describe-it ` - describe()/it() (Pest) or test class organisation (PHPUnit) \n- ` pest-datasets ` - with() datasets (Pest) or \\#\\[DataProvider\\] (PHPUnit) \n- ` pest-hooks ` - beforeEach/afterEach (Pest) or setUp/tearDown (PHPUnit)\n\n \n\n## Essential Patterns\n\n \n\n### Pest\n\n \n\n```\n<?php\n\nuse App\\Models\\User;\nuse Illuminate\\Foundation\\Testing\\RefreshDatabase;\n\nuses(RefreshDatabase::class);\n\ntest('authenticated user can create a post', function () {\n    $user = User::factory()->create();\n\n    $this->actingAs($user)\n        ->postJson('/api/posts', ['title' => 'Hello World', 'body' => 'Content.'])\n        ->assertStatus(201)\n        ->assertJsonPath('data.title', 'Hello World');\n\n    $this->assertDatabaseHas('posts', ['title' => 'Hello World', 'user_id' => $user->id]);\n});\n```\n\n \n\n### PHPUnit\n\n \n\n```\n<?php\n\nnamespace Tests\\Feature;\n\nuse App\\Models\\User;\nuse Illuminate\\Foundation\\Testing\\RefreshDatabase;\nuse Tests\\TestCase;\n\nclass PostControllerTest extends TestCase\n{\n    use RefreshDatabase;\n\n    public function test_authenticated_user_can_create_a_post(): void\n    {\n        $user = User::factory()->create();\n\n        $this->actingAs($user)\n            ->postJson('/api/posts', ['title' => 'Hello World', 'body' => 'Content.'])\n            ->assertStatus(201)\n            ->assertJsonPath('data.title', 'Hello World');\n\n        $this->assertDatabaseHas('posts', ['title' => 'Hello World', 'user_id' => $user->id]);\n    }\n}\n```\n\n \n\n## How to Use\n\n \n\nRead individual rule files for detailed explanations and code examples.\n\n \n\nEach rule file contains:\n\n \n\n- YAML frontmatter with metadata (title, impact, tags) \n- Brief explanation of why it matters \n- Bad Example with explanation \n- Good Example with both Pest and PHPUnit where syntax differs \n- Laravel 13 specific context and references\n\n \n\n## Full Compiled Document\n\n \n\nFor the complete guide with all rules expanded: ` AGENTS.md `\n\n \n\n## Files\n\n \n\n- ` AGENTS.md ` \n- ` LICENSE ` \n- ` README.md ` \n- ` SKILL.md ` \n- ` SOURCE.md ` \n- ` metadata.json ` \n- ` rules/auth-acting-as.md ` \n- ` rules/auth-sanctum.md ` \n- ` rules/db-assert-has.md ` \n- ` rules/db-assert-missing.md ` \n- ` rules/db-assert-soft-deletes.md ` \n- ` rules/factory-define.md ` \n- ` rules/factory-relationships.md ` \n- ` rules/factory-sequences.md ` \n- ` rules/factory-states.md ` \n- ` rules/fake-ai-agent.md ` \n- ` rules/fake-ai-data.md ` \n- ` rules/fake-ai-media.md ` \n- ` rules/fake-event.md ` \n- ` rules/fake-mail.md ` \n- ` rules/fake-notification.md ` \n- ` rules/fake-queue.md ` \n- ` rules/fake-storage.md ` \n- ` rules/http-assert-json-fluent.md ` \n- ` rules/http-assert-response.md ` \n- ` rules/http-refresh-database.md ` \n- ` rules/http-test-structure.md ` \n- ` rules/pest-datasets.md ` \n- ` rules/pest-describe-it.md ` \n- ` rules/pest-hooks.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/laravel-testing)\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/laravel-testing#webpage",
                "url": "https://delaparra-services.nl/skills/laravel-testing",
                "name": "Laravel 13 Testing — Pest PHP 4 & PHPUnit 12 | DeLaParra Services",
                "description": "Laravel 13 testing with Pest PHP 4 or PHPUnit 12. Use when writing feature tests, unit tests, or any test code in a Laravel application. Triggers on tasks involving HTTP tests, model factories, database assertions, mocking facades, authentication testing, or test organisation patterns.",
                "isPartOf": {
                    "@id": "https://delaparra-services.nl/#website"
                },
                "about": {
                    "@id": "https://delaparra-services.nl/#practice"
                },
                "inLanguage": "en",
                "breadcrumb": {
                    "@id": "https://delaparra-services.nl/skills/laravel-testing#breadcrumb"
                }
            },
            {
                "@type": "BreadcrumbList",
                "@id": "https://delaparra-services.nl/skills/laravel-testing#breadcrumb",
                "itemListElement": [
                    {
                        "@type": "ListItem",
                        "position": 1,
                        "name": "Home",
                        "item": "https://delaparra-services.nl/"
                    },
                    {
                        "@type": "ListItem",
                        "position": 2,
                        "name": "Laravel 13 Testing — Pest PHP 4 & PHPUnit 12"
                    }
                ]
            },
            {
                "@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/laravel-testing#skill",
                "url": "https://delaparra-services.nl/skills/laravel-testing",
                "name": "Laravel 13 Testing — Pest PHP 4 & PHPUnit 12",
                "description": "Laravel 13 testing with Pest PHP 4 or PHPUnit 12. Use when writing feature tests, unit tests, or any test code in a Laravel application. Triggers on tasks involving HTTP tests, model factories, database assertions, mocking facades, authentication testing, or test organisation patterns.",
                "inLanguage": "en",
                "license": "https://spdx.org/licenses/MIT.html",
                "subjectOf": {
                    "@id": "https://delaparra-services.nl/skills/laravel-testing#dataset"
                }
            },
            {
                "@type": "Dataset",
                "@id": "https://delaparra-services.nl/skills/laravel-testing#dataset",
                "name": "Laravel 13 Testing — Pest PHP 4 & PHPUnit 12",
                "description": "Laravel 13 testing with Pest PHP 4 or PHPUnit 12. Use when writing feature tests, unit tests, or any test code in a Laravel application. Triggers on tasks involving HTTP tests, model factories, database assertions, mocking facades, authentication testing, or test organisation patterns.",
                "url": "https://delaparra-services.nl/skills/laravel-testing",
                "identifier": "https://delaparra-services.nl/skills/laravel-testing#dataset",
                "about": {
                    "@id": "https://delaparra-services.nl/skills/laravel-testing#skill"
                },
                "creditText": "AsyrafHussin/agent-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": "laravel-testing.csv",
                        "encodingFormat": "text/csv",
                        "contentUrl": "https://delaparra-services.nl/skills/laravel-testing.csv",
                        "inLanguage": "en",
                        "dateModified": "2026-11-28T14:00:12+00:00",
                        "license": "https://spdx.org/licenses/MIT.html"
                    },
                    {
                        "@type": "DataDownload",
                        "name": "laravel-testing.json",
                        "encodingFormat": "application/json",
                        "contentUrl": "https://delaparra-services.nl/skills/laravel-testing.json",
                        "inLanguage": "en",
                        "dateModified": "2026-11-28T14:00:12+00:00",
                        "license": "https://spdx.org/licenses/MIT.html"
                    },
                    {
                        "@type": "DataDownload",
                        "name": "laravel-testing.md",
                        "encodingFormat": "text/markdown",
                        "contentUrl": "https://delaparra-services.nl/skills/laravel-testing.md",
                        "inLanguage": "en",
                        "dateModified": "2026-11-28T14:00:12+00:00",
                        "license": "https://spdx.org/licenses/MIT.html"
                    },
                    {
                        "@type": "DataDownload",
                        "name": "laravel-testing.pdf",
                        "encodingFormat": "application/pdf",
                        "contentUrl": "https://delaparra-services.nl/skills/laravel-testing.pdf",
                        "inLanguage": "en",
                        "dateModified": "2026-11-28T14:00:12+00:00",
                        "license": "https://spdx.org/licenses/MIT.html"
                    },
                    {
                        "@type": "DataDownload",
                        "name": "laravel-testing.zip",
                        "encodingFormat": "application/zip",
                        "contentUrl": "https://delaparra-services.nl/skills/laravel-testing.zip",
                        "inLanguage": "en",
                        "dateModified": "2026-11-28T14:00:12+00:00",
                        "license": "https://spdx.org/licenses/MIT.html"
                    },
                    {
                        "@type": "DataDownload",
                        "name": "laravel-testing-files.zip",
                        "encodingFormat": "application/zip",
                        "contentUrl": "https://delaparra-services.nl/skills/laravel-testing/download",
                        "inLanguage": "en",
                        "dateModified": "2026-11-28T14:00:12+00:00",
                        "license": "https://spdx.org/licenses/MIT.html"
                    }
                ]
            }
        ]
    }
}