Przejdź do treści
Biblioteka skilli
Programowanie · Testowanie

laravel-testing

/laravel-testing

Pomaga pisać testy Laravel w Pest i PHPUnit, dobierać atrapy, konfigurować fabryki i testy przeglądarkowe oraz odtwarzać błędy.

Licencja
MIT
Ostatnia zmiana repozytorium
28.09.2026

Ocena i bezpieczeństwo

90/ 100Klasa: dobry
Format25 / 25
Frontmatter z nazwą i opisem, poprawna nazwa, opis do 1024 znaków, nazwa zgodna z folderem.
Odkrywalność25 / 25
Opis mówi, kiedy użyć skilla, ma sensowną długość i jest w 3. osobie.
Treść25 / 35
Co najmniej 150 słów i do 500 linii, nagłówki, listy kroków, przykłady albo kod.
Higiena15 / 15
Bez zaślepek typu TODO, bez ścieżek Windows, z licencją.
Ryzykobrak sygnałów w skanie
Pliki w paczce
1
Skrypty
0
Komentarze HTML
0
Adresy URL w SKILL.md
0
Przestarzałość

Brak sygnałów. Repozytorium zmienione 28.09.2026, bez odwołań do wycofanych modeli i API.

Licencja

MIT, otwarta: można używać i zmieniać, z zachowaniem informacji o autorze.

Co robi i kiedy

Pomaga pisać testy Laravel w Pest i PHPUnit, dobierać atrapy, konfigurować fabryki i testy przeglądarkowe oraz odtwarzać błędy.

Oryginalny opis (EN)

The Laravel test-authoring cookbook — fakes with exact assertion syntax, Pest v4 browser testing vs Dusk, factory states + sequences, time control, DB strategies. Use when writing or reviewing Pest / PHPUnit tests, reproducing a bug as a regression test, choosing between fakes and mocks, or setting up browser tests. Recipes only — test strategy and Ship / Hold verdicts stay with qa-engineer.

Jak działa

  1. Fakes — assertion syntax
  2. Time
  3. Factories
  4. Browser tests
  5. Livewire / Inertia / Filament
  6. Coverage that must exist
Sekcje z nagłówków SKILL.md, w oryginale · 50 linii, 444 słów
Podgląd SKILL.md
---
name: laravel-testing
description: "The Laravel test-authoring cookbook — fakes with exact assertion syntax, Pest v4 browser testing vs Dusk, factory states + sequences, time control, DB strategies. Use when writing or reviewing Pest / PHPUnit tests, reproducing a bug as a regression test, choosing between fakes and mocks, or setting up browser tests. Recipes only — test strategy and Ship / Hold verdicts stay with qa-engineer."
---

# Laravel Testing Cookbook

Match the project first: Pest vs PHPUnit from `composer.json`, DB strategy from existing tests (`RefreshDatabase` — transaction-based, skips migrating when the schema is current — vs `DatabaseMigrations` / `DatabaseTruncation`, both slower full resets needed for browser tests). Seeding: prefer L13's `#[Seed]` / `#[Seeder(OrderStatusSeeder::class)]` attributes over manual `$this->seed()` boilerplate; `#[UnitTest]` on a pure-logic method skips booting the app for just that test. Never introduce a second runner or strategy.

## Fakes — assertion syntax

Fake the framework primitive, assert the interaction. Never mock what Laravel fakes.

| Primitive | Setup | Assert |
|---|---|---|
| Mail | `Mail::fake()` | `Mail::assertSent(OrderShipped::class, fn ($m) => $m->hasTo($user->email))` · `assertQueued` · `assertNothingSent` |
| Notification | `Notification::fake()` | `Notification::assertSentTo($user, InvoicePaid::class, fn ($n, $channels) => in_array('mail', $channels))` |
| Queue / Bus | `Queue::fake()` / `Bus::fake()` | `Bus::assertDispatched(ProcessOrder::class, fn ($job) => $job->order->is($order))` · `assertChained` · `assertBatched` · `assertNotDispatched` |
| Event | `Event::fake([OrderShipped::class])` | `Event::assertDispatched(OrderShipped::class)` — **always pass the allowlist**: a bare `Event::fake()` suppresses model events and factories break silently |
| HTTP | `Http::fake(['api.stripe.com/*' => Http::response(['id' => 'ch_1'], 200)])` | `Http::assertSent(fn (Request $r) => $r->url() === … && $r['amount'] === 500)`. Fake success, 4xx, 5xx, and `Http::failedConnection()` timeout |
| Storage | `Storage::fake('avatars')` | `Storage::disk('avatars')->assertExists($path)` · `assertMissing` |
| Process | `Process::fake(['git *' => Process::result('ok')])` | `Process::assertRan(fn ($p) => str_contains($p->command, 'git'))` |

Jobs: `Bus::fake()` proves dispatch; invoking `$job->handle()` directly proves effect. Test both, plus `failed()`.

## Time

`$this->travelTo(now()->addDays(30))`, `$this->freezeTime()`, `$this->travelBack()`. Any TTL, expiry, or scheduling logic gets a time-travel test — never `sleep()`.

## Factories

- States for variants: `OrderFactory::new()->paid()->forUser($user)`. Never hand-build models in tests.
- `Sequence` for controlled variation: `->state(new Sequence(['status' => 'active'], ['status' => 'churned']))`.
- Relationships: `->has(Post::factory()->count(3))` / `->for($team)`. `recycle($tenant)` to share one parent across the tree — the multi-tenant test essential.
- `Model::factory()->make()->getAttributes()` for validation-payload arrays (doc-backed; `->raw()` exists but is undocumented).

## Browser tests

Detect first, then match: `pestphp/pest-plugin-browser` (Pest v4 — current) vs `laravel/dusk` (legacy — keep, don't migrate mid-PR).
Pest v4: `visit('/dashboard')->assertSee(…)`, plus free checks Dusk lacks — `assertNoJavascriptErrors()`, `assertNoConsoleLogs()`, `assertNoAccessibilityIssues()`. Use them on every page test.

## Livewire / Inertia / Filament

- Livewire: `Livewire::test(CreateOrder::class)->set('email', 'x@y.z')->call('save')->assertHasNoErrors()->assertDispatched('order-created')`.
- Inertia: `$this->get(route('orders.index'))->assertInertia(fn (Assert $page) => $page->component('Orders/Index')->has('orders', 3))`.
- Filament: `livewire(CreateOrder::class)->fillForm([...])->call('create')->assertNotified()`.

## Coverage that must exist

- Every protected endpoint: one allowed + one denied authorization test (403), and an unauthenticated test (401) for APIs.
- Every validation rule that guards money, quantity, or state: a failing-input test asserting `assertJsonValidationErrors` (APIs) or `assertInvalid` / `assertRedirectBackWithErrors` (classic web forms).
- Every production bug: a regression test that fails on the old code. Name it after the bug.
- Feature tests assert three layers: status, shape (`assertJsonPath`, `assertJsonStructure`), and DB state (`assertDatabaseHas`, `assertDatabaseCount`).

Wersje

RepozytoriumWynikLicencja
Ta strona · hamzaalayed/laravel-claude-agents90MIT
HoangNguyen0403/agent-skills-standard100MIT
fusengine/agents100MIT
foysal50x/skills100MIT
AsyrafHussin/agent-skills100MIT

Identyczna treść występuje jeszcze w 2 innych folderach na GitHubie. Tu pokazujemy jedną, najlepiej ocenioną kopię.

Migawka bazy z 13.11.2026 · wersja paczki 9008c0726343 (skrót SHA-256 całej paczki)

Pobrania w ostatnich 30 dniach: 0 · ranking

: szkodliwa treść, błędny opis albo prośba autora o usunięcie.

Podobne skille

  • 95laravel-tdd
    Opisuje testowanie w Laravel z PHPUnit i Pest: fabryki modeli, testy HTTP, uwierzytelnianie Sanctum, mocki i pokrycie, także przy pisaniu funkcji od testu.
  • 96laravel-tdd
    Prowadzi test-driven development w Laravel z PHPUnit i Pest, obejmując fabryki, testy bazy i cele pokrycia.
  • 100php-testing
    Pomaga pisać i konfigurować testy w projekcie PHP bez Laravela, z wyborem między PHPUnit a Pest.
  • 95laravel-tdd
    Pisze testy Laravel w PHPUnit lub Pest, z fabrykami modeli, testami HTTP, uwierzytelnianiem Sanctum i mockami, także metodą TDD.
  • 100pest-testing
    Pomaga pisać i naprawiać testy Pest PHP w projektach Laravel, także przy konwersji z PHPUnit i testach przeglądarkowych.
  • 100testing-laravel
    Pisze testy Laravel w PHPUnit: testy funkcji i jednostkowe, mocki, fabryki i testy kontrolerów, modeli, zadań oraz endpointów API.

Uwagi i zgłoszenia

Wiadomość trafi do Bartosza Sokolińskiego. Adres e-mail jest potrzebny tylko do odpowiedzi. Szczegóły w polityce prywatności.