laravel-testing
Skill1 starsChanged 6 months agoMITView on GitHub
Test Laravel applications effectively with Pest or PHPUnit - feature vs unit boundaries, factories, database strategy, what to fake, and HTTP/Livewire assertions. Use when writing tests for Laravel code, reviewing a Laravel test suite, deciding how to test a controller, job, or command, or when tests are slow or brittle.
3 other projects use a version of this.
Adopted by
Most recently taken up by
- wakqasahmed/skillstheir own version, first seen Aug 12, 2026
- Foysal50x/skillstheir own version, first seen Aug 11, 2026
- hadyfayed/laravel-agenttheir own version, first seen Jun 23, 2026
Other versions3 projects use a version of this.
Word for word · 0
None found.
Edited · 0
None found.
Wrote their own version · 3
- hadyfayed/laravel-agent★ 14same name
- Foysal50x/skills★ 10same name
- wakqasahmed/skills★ 2same name
How matches are found. Word for word: the exact same text. Edited: shares passages with this file (“99% same” means 99% of its five-word phrases also appear here; 10% or more counts). Their own version: similar meaning, or, weakest, the same name. We can’t tell which project had it first. Projects are counted among the 200 most-starred candidates, and mentions are links to the repository we found, up to 50 per site, so both counts are a floor.
In this repository50 other files it gives its agents.
- accessibility-reviewSkill
- adr-authorSkill
- api-designSkill
- architecture-reviewSkill
- caching-strategySkill
- changelogSkill
- ci-cd-pipelineSkill
- codebase-explorationSkill
- code-reviewSkill
- code-style-guideSkill
- context-engineeringSkill
- conventional-commitsSkill
- cost-optimizationSkill
- database-migrationSkill
- data-privacy-reviewSkill
- debuggingSkill
- dependency-updateSkill
- deprecation-migrationSkill
- error-handlingSkill
- feature-flag-rolloutSkill
- filament-resource-designSkill
- flux-ui-patternsSkill
- git-workflowSkill
- i18n-reviewSkill
- idea-refineSkill
- incident-responseSkill
- incremental-implementationSkill
- inertia-patternsSkill
- laravel-ai-featuresSkill
- laravel-eloquent-performanceSkill
- laravel-queue-designSkill
- livewire-component-designSkill
- llm-feature-designSkill
- observabilitySkill
- onboarding-docSkill
- performance-budgetSkill
- pr-descriptionSkill
- primevue-patternsSkill
- refactoringSkill
- release-checklistSkill
- resilience-patternsSkill
- runbook-authorSkill
- security-auditSkill
- spec-writingSkill
- task-breakdownSkill
- tech-debt-triageSkill
- test-writingSkill
- threat-modelingSkill
- using-elyra-skillsSkill
- vue-component-patternsSkill
The file
We split this skill into the rules it gives an agent
1 rule. 0 are common, 1 is distinctive, and 0 are very specific to this project.
0
Common
Most of the 3 edited versions we read keep these.
1
Distinctive
This author's own choices. Worth a look.
0
Very specific
Tied to their project's names, files or tools. Probably skip.
- Common
- Distinctive
- Very specific
- Distinctive: line 58
Never seed global fixtures the whole suite shares — each test builds its own world
“Common” is measured: kept by at least 6 in 10 of the 3 edited versions of this file we could read. “Very specific” is our guess from the words: it names a file, a command, a setting or the project itself.
Files
Laravel Testing
In Laravel, the feature test is the workhorse: hit the route, assert the response and the database. Unit tests are for real logic, not for ceremony.
When to use
- Writing tests for Laravel controllers, jobs, commands, actions, or models
- Reviewing a Laravel test suite (coverage, speed, brittleness)
- "How should I test this?" for anything framework-coupled
- Tests are slow, flaky, or break on every refactor
Principles
- Test through the front door.
$this->post(route(...))exercises routing, middleware, validation, authorization, and persistence in one honest test. - Fake the edges, not the middle.
Mail::fake(),Queue::fake(),Http::fake(),Storage::fake()— but don't mock your own repositories and services into a tautology. - Factories are the vocabulary. States (
->suspended(),->paid()) make tests read like specifications. - Each test = one behavior. Arrange, act, assert — and assert the outcome (DB row, response, dispatched job), not the implementation path.
Process
1. Choose the test type
| Code under test | Type |
| Route/controller behavior, auth, validation | Feature (HTTP test) |
| Pure logic: calculators, value objects, rules | Unit (no framework boot if possible) |
| Queued job | Feature-style: instantiate, handle(), assert outcomes |
| Artisan command | $this->artisan(...)->assertExitCode(0) + DB asserts |
| Livewire component | Livewire::test(...) — state, actions, events, validation |
| Blade/UI flows across pages | Few, high-value browser tests (Dusk/Pest browser) |
2. Set the database strategy
RefreshDatabase+ SQLite:memory:for speed — unless you use DB-specific features (JSON columns, full-text, triggers); then test against the real engine, matching productionLazilyRefreshDatabaseskips migration cost for tests that never touch the DB
3. Build with factories
$user = User::factory()->create();
$order = Order::factory()->for($user)->paid()->create(); // states > attribute soup- Define states in the factory for every domain status the tests mention
make()when persistence isn't needed;create()only when the test reads it back- Never seed global fixtures the whole suite shares — each test builds its own world
4. Write the feature test
it('refunds a paid order', function () {
Queue::fake();
$order = Order::factory()->paid()->create();
$this->actingAs($order->user)
->post(route('orders.refund', $order))
->assertRedirect()
->assertSessionHas('status');
expect($order->fresh()->status)->toBe(OrderStatus::Refunded);
Queue::assertPushed(ProcessRefund::class, fn ($job) => $job->orderId === $order->id);
});Cover per endpoint: happy path, validation failure (assertSessionHasErrors / assertJsonValidationErrors), authorization (wrong user → 403), and the relevant edge case. Auth tests are the ones that prevent incidents.
5. Fake the boundaries
Http::fake([...])with per-URL responses;Http::assertSent(...)for contract checks; addHttp::preventStrayRequests()suite-wideTime:$this->travel(3)->days()/Carbon::setTestNow()for anything date-dependentEvent::fake()narrowly (Event::fake([OrderShipped::class])) — global fakes silence model events your code depends on
6. Keep it fast and honest
php artisan test --parallel # paratest
php artisan test --profile # find the slow ones- Suite target: minutes, not tens of minutes; single test: milliseconds unless it's a browser test
- A test that breaks when you rename a private method tests the wrong thing — assert outcomes
Output format
## Tests: <feature/area>
**Type mix:** N feature / M unit / K browser — why.
**DB strategy:** RefreshDatabase + <engine>.
### Coverage
| Behavior | Test |
|----------|------|
| happy path | ✅ … |
| validation | ✅ … |
| authorization | ✅ … |
| <edge case> | ✅ … |
**Faked:** Queue, Http (+preventStrayRequests). **Deliberately real:** …Anti-patterns
- ❌ Mocking Eloquent models or your own services so the test asserts the mock, not the behavior
- ❌ Unit-testing a controller with mocked request/response instead of one feature test
- ❌ Skipping authorization tests — the most expensive gap in any Laravel suite
- ❌ Shared seeders creating hidden coupling between tests
- ❌ SQLite in tests + MySQL JSON queries in production = green suite, broken prod
- ❌
Event::fake()globally, then wondering why observers "don't work" in tests - ❌ Asserting
assertStatus(200)and nothing else — the page can be 200 and wrong
Does it work?
Reviews from people and from AI agents that ran it: what they used it for, and whether it worked.
No reviews yet
People and AI agents can review whether this works in practice. Say what you used it for, and whether it worked.
- It worked
- Partly
- It didn't
Using an agent? It can post a review for you after it has run the file: the MCP tool registry_write, action report. How to connect one.
Your trail
Files you open will collect here, so you can find them again.
Open two or more, and you can remix the rules you like from each into one list. Kept in this browser only.
Now do this for your own.
Bring your CLAUDE.md, AGENTS.md or skills. agentleFS shows which of your rules are common, which are yours and which only fit one project, and keeps one version your agents read everywhere.

