Works with the AI Agents you already use

    Claude CodeClaude CodeCursorCursorCodex CLICodex CLIDeepSeekDeepSeekMuseMuse+22 more

    Laravel Testing with Pest and PHPUnit

    by Saizul Amin

    1

    Write, fix, and audit Laravel test suites using Pest or PHPUnit with best-practice fakes and factories.

    $5

    Secure checkout via Stripe

    Money-back guarantee

    Converts to your local currency at checkout

    Security scanned
    Laravel Testing with Pest and PHPUnit

    Laravel Testing with Pest and PHPUnit

    Example session with this skill installed

    Run the Laravel Testing with Pest and PHPUnit skill on my project and give me a prioritised list of what to fix, with exact changes.

    • Read your context and instructions
    • Compiled the laravel testing

    Here is what the Laravel Testing with Pest and PHPUnit skill produced.

    Demo: real, unedited output of the skill's bundled script on a sample input from its test suite.

    Output

    test smells: 1 high, 5 medium, 6 low, 2 info
    HIGH   tests/Feature/PostTest.php:11  [focused-test] focused test with ->only(): CI runs only this test
           fix: Remove ->only() before committing.
    MEDIUM tests/Feature/InvoiceTest.php:12  [no-db-reset] uses the database but never resets it
           fix: Add use RefreshDatabase (PHPUnit) or pest()->use(RefreshDatabase::class)->in('Feature').
    MEDIUM tests/Feature/PostTest.php:8  [no-db-reset] uses the database but never resets it
           fix: Add use RefreshDatabase (PHPUnit) or pest()->use(RefreshDatabase::class)->in('Feature').
    MEDIUM tests/Feature/PostTest.php:14  [real-http] outgoing HTTP without Http::fake()
           fix: Call Http::fake([...]) and Http::preventStrayRequests() so tests never hit real APIs.
    MEDIUM tests/Feature/PostTest.php:15  [sleep] sleep() slows the suite and makes it flaky
           fix: Use $this->travel(5)->minutes(), Carbon::setTestNow() or Sleep::fake() (Laravel 10+).
    MEDIUM tests/Feature/PostTest.php:16  [debug-output] dd() in a test
           fix: Remove it; use assertions or ->dump() locally only.
    LOW    tests/Feature/InvoiceTest.php:10  [no-assertions] test 'test_invoice_page_loads' has no assertion
           fix: Assert the outcome (assertOk(), assertDatabaseHas(), expect()->toBe()).
    LOW    tests/Feature/InvoiceTest.php:13  [hard-coded-id] hard-coded id in URL /api/invoices/42
           fix: Create the model with a factory and use route('posts.show', $post) or "/posts/{$post->id}".
    LOW    tests/Feature/PostTest.php:10  [hard-coded-id] hard-coded id in URL /posts/1
           fix: Create the model with a factory and use route('posts.show', $post) or "/posts/{$post->id}".
    LOW    tests/Feature/PostTest.php:12  [no-assertions] test 'syncs to the crm' has no assertion
           fix: Assert the outcome (assertOk(), assertDatabaseHas(), expect()->toBe()).
    LOW    tests/Feature/PostTest.php:18  [no-assertions] test 'creates a post' has no assertion
           fix: Assert the outcome (assertOk(), assertDatabaseHas(), expect()->toBe()).
    LOW    tests/Feature/PostTest.php:21  [without-middleware] withoutMiddleware() disables auth, CSRF and throttling
           fix: Authenticate with actingAs() instead, or disable only one middleware class.
    INFO   tests/Feature/InvoiceTest.php:24  [skipped] skipped or incomplete test
           fix: Fix or delete it; track the reason in an issue.
    INFO   tests/Feature/PostTest.php:24  [skipped] skipped or incomplete test
           fix: Fix or delete it; track the reason in an issue.
    

    What you do next

    1. Fix the highest-severity items first.
    2. Ask your agent to apply the fixes it suggests, then run the skill again to confirm.
    3. Keep the skill installed and re-run it whenever the project changes.

    Connects securely to your tools. The creator never sees your data.

    About this skill

    Testing in Laravel often suffers from slow execution, flaky database states, and leaked external API calls. This skill provides a systematic approach to writing and auditing Laravel test suites using Pest or PHPUnit. It ensures your tests remain fast and deterministic by enforcing the use of factories, service fakes, and proper database lifecycle management.

    What it does

    • Write feature tests for HTTP routes, JSON APIs, and Livewire components with proper status and JSON path assertions.
    • Isolate side effects by implementing fakes for Mail, Notifications, Queues, Events, and the HTTP client.
    • Audit test quality using a built-in scanner to find "smells" like hard-coded IDs, missing database traits, or forgotten ->only() calls.
    • Manage test data via Eloquent factories with states and relationships instead of manual database seeding.
    • Standardize suites by converting legacy PHPUnit tests to Pest or setting up parallel testing environments.

    How it works

    1. Detect stack by analyzing composer.json and phpunit.xml to match the project's testing framework and database configuration.
    2. Scan for smells using the provided Python utility to identify high-risk issues like real HTTP calls or missing assertions.
    3. Generate tests based on the target code, applying specific patterns for controllers, jobs, or policies.
    4. Execute and verify tests using php artisan test, ensuring coverage and addressing any failures without weakening assertions.

    Frameworks & tools

    Laravel 10 through 12, Pest 2 or 3, PHPUnit 10 or 11, and Python 3.8 for the scanner utility.

    Why this beats prompting it yourself

    Generic prompts often produce tests with hard-coded URLs and brittle database setups. This skill enforces Laravel-specific best practices like RefreshDatabase, Http::preventStrayRequests(), and route naming, resulting in a suite that is easier to maintain and resistant to environmental drift.

    Use cases

    • Add comprehensive feature tests for a new JSON API endpoint including validation and auth.
    • Identify why a test suite is running slowly or failing intermittently in CI.
    • Refactor a folder of PHPUnit tests into clean, modern Pest syntax.
    • Ensure all external integrations are properly mocked using Laravel Fakes.

    Known limitations

    Does not support browser-based E2E testing with Laravel Dusk or Playwright. Requires PHP 8.2 and Composer dependencies installed to execute the tests.


    Open source: saizul/laravel-php-skills on GitHub (MIT licence, by Saizul Amin).

    Find more skills like this on the Claude Skills Marketplace, the Codex Skills Marketplace and the Gemini Skills Marketplace, or browse Claude Skills for APIs & Backend.

    No support for Laravel Dusk or Playwright. Requires PHP 8.2+. Does not handle static analysis or N+1 query detection.

    How to use

    1. 1

      Connect your agent to the Agensi MCP

      Copy the prompt and paste it into Claude, ChatGPT, Cursor or any agent that supports MCP. It sets up the connection for you. Manual setup

    2. 2

      Sign in to Agensi

      Your agent shows a sign-in link. Sign in and click Allow.

    3. 3

      Ask for what you need

      Your agent loads this skill and uses it on your task. It always asks before buying a skill.

    Reviews

    No reviews yet

    Be one of the first to try it. Every listed skill goes through the trust checks below.

    Security scanned

    Checked by our 8-point scan before listing

    Fresh listing

    Recently published to Agensi

    Money-back guarantee

    Doesn't do what its page promises? You get your money back.

    Frequently Asked Questions

    The skill automates the creation of feature and unit tests, audits existing suites for 'smells' like real HTTP calls, and can refactor legacy PHPUnit tests into modern Pest syntax while enforcing Laravel best practices.

    It supports Laravel versions 10 through 12, utilizing Pest 2/3 or PHPUnit 10/11, and requires a local environment with PHP 8.2+ to execute and verify the generated suites.

    Unlike generic prompts, this skill uses a specialized scanner to identify project-specific database configurations and prevents common mistakes like hard-coded IDs or missing side-effect fakes.

    The package includes the core AI skill logic, a Python-based utility for scanning test 'smells,' and predefined templates for controllers, jobs, and policies.

    No, this skill focuses on high-performance backend testing (Feature/Unit); it does not currently support browser-based end-to-end testing via Laravel Dusk or Playwright.

    The skill is designed to work with any AI agent platform that supports custom tool integration and has access to your local or remote file system to analyze code.

    New in APIs & Backend