laravel-testing

Write feature, unit, and architecture tests for Laravel 13 applications using Pest 4 and PHPUnit 12.

1|Updated Jul 29, 2026
One-click install
npx skills add https://github.com/fusengine/kimi-code --skill laravel-testing-fusengine
Or copy as Structured Prompt for Agent▼
Please help me install this Agent Skill.
Skill: laravel-testing
Source: https://github.com/fusengine/kimi-code/tree/main/plugins/laravel-expert/skills/laravel-testing
Command: npx skills add https://github.com/fusengine/kimi-code --skill laravel-testing-fusengine

SYSTEM DOCUMENTATION & REQUIREMENTS

💡 This Skill includes references (resource) components.

What problem does it solve? Writing comprehensive Laravel tests requires knowing dozens of assertion APIs, mocking strategies, and Pest/PHPUnit conventions, and mistakes lead to flaky, slow, or incomplete test suites. ## Core Features & Use Cases - Full Test Coverage Guidance: Covers feature tests (HTTP, JSON APIs, authentication), unit tests (services, policies, rules), and Pest architecture tests enforcing code structure. - Mocking & Faking References: Detailed patterns for Mail, Queue, Event, Notification, Storage, Bus fakes, Http::fake for external APIs, and time travel helpers. - Ready-to-Use Templates: Provides FeatureTest, UnitTest, ApiTest, ArchTest, and Pest configuration templates to scaffold test suites immediately. - Use Case: When adding a new REST endpoint to a Laravel 13 app, use this Skill to generate a complete API test with Sanctum authentication, JSON structure assertions, database checks, and validation error coverage. ## Quick Start Write a Pest feature test for my Laravel posts API endpoint including authentication, validation errors, and database assertions.

Frequently Asked Questions about laravel-testing

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

FAQPage Schema
How do I write feature tests in Laravel with Pest?▼

Use it() or describe() blocks with $this->get(), post(), or postJson() to make requests, then chain assertions like assertOk() or assertJsonPath(). Apply the RefreshDatabase trait via uses() in Pest.php for database isolation.

How to mock external HTTP APIs in Laravel tests?▼

Use Http::fake() with URL patterns mapped to Http::response() stubs, and call Http::preventStrayRequests() to fail on unmocked calls. Verify requests afterward with Http::assertSent() and closure-based matchers.

Pest vs PHPUnit for Laravel testing: which should I use?▼

Laravel 13 supports both Pest 4 and PHPUnit 12. Pest offers a concise BDD syntax with datasets and arch() tests, while PHPUnit uses class-based tests with PHP attributes like #[Test] and #[Seed]. Both run through the same php artisan test command.

Does Laravel testing support testing queued jobs and events?▼

Yes, use Queue::fake() and Event::fake() before triggering actions, then assert with Queue::assertPushed() and Event::assertDispatched(). Closures let you verify payload contents, and Bus::fake() covers batched and chained jobs.

Why are my Laravel tests slow and how do I fix it?▼

Slow tests usually come from hitting a real database or running sequentially. Configure sqlite :memory: in phpunit.xml, run ./vendor/bin/pest --parallel, and use --profile to identify the slowest tests.

How do I test authenticated API routes with Sanctum?▼

Call Sanctum::actingAs($user, ['abilities']) before making requests to authenticate without real tokens. For web routes, use $this->actingAs($user) with an optional guard name, and verify state with assertAuthenticated() or assertGuest().