plugins/laravel-expert/skills/laravel-testing/SKILL.md
Write tests with Pest 4/PHPUnit 12, feature tests, unit tests, mocking, fakes, and factories. Use when testing controllers, services, models, or implementing TDD on Laravel 13.
npx skillsauth add fusengine/agents laravel-testingInstall this skill globally with one command. Works with Claude Code, Cursor, and Windsurf.
3 of 9 scanners reported clean
Some scanners were skipped, did not run, or reported a non-clean status. Review each row below.
Before ANY implementation, use TeamCreate to spawn 3 agents:
After implementation, run fuse-ai-pilot:sniper for validation.
| Type | Purpose | Location |
|------|---------|----------|
| Feature | HTTP, full stack | tests/Feature/ |
| Unit | Isolated classes | tests/Unit/ |
| Arch | Code architecture | tests/Arch.php |
What to test?
├── HTTP endpoint → Feature test
├── Service/Policy logic → Unit test
├── Code structure → Arch test
├── External API → Mock with Http::fake()
├── Mail/Queue/Event → Use Fakes
└── Database state → assertDatabaseHas()
Coverage strategy?
├── Feature tests (70%) → Critical flows
├── Unit tests (25%) → Business logic
├── E2E tests (5%) → User journeys
└── Arch tests → Structural rules
pest --parallel for speed| Topic | Reference | When to Consult | |-------|-----------|-----------------| | Pest Syntax | pest-basics.md | it(), test(), describe() | | Datasets | pest-datasets.md | Data providers, hooks | | Architecture | pest-arch.md | arch() tests |
| Topic | Reference | When to Consult | |-------|-----------|-----------------| | Requests | http-requests.md | GET, POST, headers | | JSON API | http-json.md | API assertions | | Authentication | http-auth.md | actingAs, guards | | Assertions | http-assertions.md | Status, redirects |
| Topic | Reference | When to Consult | |-------|-----------|-----------------| | Basics | database-basics.md | RefreshDatabase | | Factories | database-factories.md | Factory patterns | | Assertions | database-assertions.md | DB assertions |
| Topic | Reference | When to Consult | |-------|-----------|-----------------| | Services | mocking-services.md | Mock, spy | | Fakes | mocking-fakes.md | Mail, Queue, Event | | HTTP & Time | mocking-http.md | Http::fake, travel |
| Topic | Reference | When to Consult | |-------|-----------|-----------------| | Console | console-tests.md | Artisan tests | | Troubleshooting | troubleshooting.md | Common errors |
| Template | When to Use | |----------|-------------| | FeatureTest.php.md | HTTP feature test | | UnitTest.php.md | Service unit test | | ArchTest.php.md | Architecture test | | ApiTest.php.md | REST API test | | PestConfig.php.md | Pest configuration |
// Feature test
it('creates a post', function () {
$user = User::factory()->create();
$this->actingAs($user)
->postJson('/api/posts', ['title' => 'Test'])
->assertCreated()
->assertJsonPath('data.title', 'Test');
$this->assertDatabaseHas('posts', ['title' => 'Test']);
});
// With dataset
it('validates emails', function (string $email, bool $valid) {
// test logic
})->with([
['[email protected]', true],
['invalid', false],
]);
// Mock facade
Mail::fake();
// ... action ...
Mail::assertSent(OrderShipped::class);
# Run all tests
php artisan test
# Pest directly
./vendor/bin/pest
# Parallel execution
./vendor/bin/pest --parallel
# Filter by name
./vendor/bin/pest --filter "user can"
# Coverage
./vendor/bin/pest --coverage --min=80
# Profile slow tests
./vendor/bin/pest --profile
RefreshDatabase traitLaravel 13 requires PHPUnit 12 and supports Pest 4. PHP attributes replace docblock annotations.
use PHPUnit\Framework\Attributes\Test;
use Illuminate\Foundation\Testing\Attributes\Seed;
use Illuminate\Foundation\Testing\Attributes\Seeder;
#[Seed] // runs DatabaseSeeder
#[Seeder(UserSeeder::class)] // runs a targeted seeder
final class UserTest extends TestCase
{
#[Test]
public function it_creates_user(): void { /* ... */ }
}
Laravel 13 automatically resets Str caches (random, slug) between tests to avoid state leak. No manual setup required.
pest --init regenerates Pest.php with the new APIexpect()->toBeInstanceOf() → strict typing requiredtesting
Copy self-audit and ban-lists — filler verbs/hype adjectives, slop placeholder names, fake-precise numbers, Title Case headlines, humor in error copy ('Oops!'), em-dash crutch, one copy register per page.
development
Logged-in web apps — dashboards, auth flows, settings, onboarding, data tables, command palettes, modals, toasts. Register `product`: density and glance-speed over marketing polish, no hero/CTA-tricks, every data surface covers empty/loading/error explicitly, tables and dataviz follow preattentive-processing rules.
development
Marketing sites, landing pages, campaign pages — register `brand` (design IS the product). Structure comes from the register's POV + a macrostructure pick, never from copying an inspiration site's section flow. Hero discipline, deviated section order, asymmetric grids, and a silhouette lookalike-test gate before ship.
development
Token-strategy core — OKLCH color rules, neutral tinting, accent-commitment levels, type scale, 8pt spacing grid, touch targets, and the canonical output format of design-system.md (the file the harness gates on). This is routing step 1 of design-method/SKILL.md — read it before design-web/design-webapp/design-ios/design-android, before picking or auditing a single color/type/spacing value.