Skip to content
Back to skills

Laravel Go Testing

ASecurity

Testing apps built with Laravel for Go (the go.laravel.com module, 0.2.x) with go test and laraveltest. Use when writing, reviewing or fixing tests: fakes for the queue, mail, events, notifications, the HTTP client, processes and storage; ActingAs versus real logins and API tokens; authorization; CSRF; validation, redirect, JSON, Inertia and error assertions; database assertions and factories; jobs with client.Attempt, background work, the schedule, ticks; time travel; parallel tests. Each ru...

  • 24 stars
  • 0 votes
  • 0 copies
  • 0 views
  • Added December 4, 2026
databasesgosqltestinggitapidatabasedocumentation

Works with

  • cli
  • api

Security analysis

A100/100

Pro scans all 19 files and shows the line behind each finding

Scanned December 5, 2026

npx -y skills add gabrielmoreira/agent-skills-mirror --skill laravel-go-testing --agent claude-code

Installs into .claude/skills of the current project.

Are you the author of Laravel Go Testing?

Add the live security badge to your README. It updates with every re-scan.

Security grade badge for Laravel Go Testing
[![Security: A — Skills Directory](https://www.skillsdirectory.com/api/skills/gabrielmoreira-laravel-go-testing/badge)](https://www.skillsdirectory.com/skills/gabrielmoreira-laravel-go-testing)

More formats (shields.io, HTML) on the badges page. Keep it an A: scan every change in CI with Pro.

Download with Pro
SKILL.md
---
name: laravel-go-testing
description: "Testing apps built with Laravel for Go (the go.laravel.com module, 0.2.x) with go test and laraveltest. Use when writing, reviewing or fixing tests: fakes for the queue, mail, events, notifications, the HTTP client, processes and storage; ActingAs versus real logins and API tokens; authorization; CSRF; validation, redirect, JSON, Inertia and error assertions; database assertions and factories; jobs with client.Attempt, background work, the schedule, ticks; time travel; parallel tests. Each rule shows a test that passes while the app is broken, fails for the wrong reason or is flaky (the sync queue hiding a missing delay, a fake installed after the request, stacked fakes, ActingAs hiding a broken logout or API guard, AssertValid passing on a 500, a followed redirect hiding a 500, lenient JSON and Inertia assertions, a hard-coded ID on SQLite, a second client, AssertSucceeded on a job that did nothing) and the test to write. Every example compiles against go.laravel.com v0.2.0, and the examples were run against a working and a deliberately broken test app (two rules are proved by repeated runs instead). Complements the testing skill a new app ships; for writing app code use laravel-go-best-practices."
license: MIT
metadata:
  author: AsyrafHussin
  version: "1.1.0"
  laravelGoVersion: "0.2.x (tested 0.2.0)"
  goVersion: "1.27+"
---

# Laravel for Go Testing

Testing apps built with [Laravel for Go](https://laravel.com/go) (`go.laravel.com` 0.2.x) with `go test` and `laraveltest`. Contains 28 rules across 6 categories. Every example compiles against `go.laravel.com` v0.2.0, and each "Tested on go.laravel.com v0.2.0" note records what a run on that version showed. Examples use the routes, models, jobs and fakes of a typical app (`/posts`, `/login`, `/api/me`, `jobs.ShipOrder`, `factories.Post`); adapt the names to yours.

**Version 1.1.0 (December 2026).** Laravel for Go is in beta, and a minor version before 1.0 may change the API; check APIs against the docs bundled with the version you install (`.agents/skills/writing-laravel-go-apps/scripts/docs-path.sh`, which runs `go list -m -f '{{.Dir}}/docs' go.laravel.com`). To move an app to a new version, use the `upgrading-laravel-go` skill that new apps ship in `.agents/skills/`, with the docs' `upgrade.md`.

## When to Apply

- Writing tests for a Laravel for Go app
- Reviewing a test suite: tests that pass while the app is broken, tests that fail for the wrong reason, flaky tests
- A test fails or passes and you are not sure why

## How This Skill Fits

A new app ships eight skills in `.agents/skills/`, among them `testing-laravel-go-apps`, which lists the testing tools, and `upgrading-laravel-go`. This skill covers the ways those tools give false confidence, with the test to write instead. Two corrections to the shipped skill, both still in the copy a v0.2.0 app ships:

- It calls `client.ActingAs(&user)` the tool "for session auth". `ActingAs` bypasses the session and request guards (`http-real-login-vs-acting-as`, `http-api-tokens`)
- It says never to run `schedule:run` in tests. That leaves the schedule entry untested; `schedule:run` works in a test on the test's clock (`bg-schedule-and-ticks`)

For the app code itself use `laravel-go-best-practices`.

How the examples were checked: the Incorrect tests passed against a deliberately broken version of the app, and the Correct tests failed against it and passed against the working one. Two rules are proved another way, and say so: the leftover-file case of `fake-disk` (a sequence of runs) and `setup-parallel-tests` (flaky by nature, proved by repeated runs).

## Rule Categories by Priority

| Priority | Category | Impact | Prefix |
|----------|----------|--------|--------|
| 1 | Fakes | CRITICAL | `fake-` |
| 2 | HTTP | CRITICAL | `http-` |
| 3 | Setup | HIGH | `setup-` |
| 4 | Database | HIGH | `db-` |
| 5 | Background Work | HIGH | `bg-` |
| 6 | Time | MEDIUM | `time-` |

## Quick Reference

### 1. Fakes (CRITICAL)

- `fake-queue-vs-sync` - Tests run jobs inline on `sync`: no delays, no retries; fake the queue to test what was queued and when
- `fake-install-before-the-request` - A fake installed after the request records nothing; one fake of each kind per client
- `fake-stacked-fakes` - The event fake stops the faked events' queued listeners; the notification fake stops their email
- `fake-mail-sent-vs-queued` - `AssertSentTimes` and `Emails()` ignore queued mail; `AssertNotSent` and `AssertNothingSent` check both
- `fake-http-and-processes-strict` - Unmatched requests and processes succeed; `PreventStray...` and assert the call
- `fake-notification-queued` - `AssertSentTo` passes for sent and queued alike; check `Queued`
- `fake-disk` - Without `FakeDisk`, tests write to real storage and pass on leftover files

### 2. HTTP (CRITICAL)

- `http-real-login-vs-acting-as` - `ActingAs` skips the session; test login and logout through the routes
- `http-api-tokens` - `ActingAs` skips request guards; send a real token
- `http-authorization-matrix` - Guest, another user, owner; check the row after each denial
- `http-csrf-cross-site` - The client is same-origin; send a cross-site request to test CSRF
- `http-assert-valid-is-not-success` - `AssertValid` passes on a `500`; check the outcome
- `http-redirects-are-followed` - Assertions after `AssertRedirect` read the landing page; `WithoutRedirects` for the redirect itself
- `http-json-exhaustive` - `AssertJSON` and `AssertJSONMissing` are lenient; `AssertJSONMatches` without `Etc`, `AssertJSONMissingPath`
- `http-inertia-scope` - `AssertProp` checks one path; `Scope` checks every field
- `http-check-the-error` - `AssertNothingReported`, `AssertError`, and paths from route names

### 3. Setup (HIGH)

- `setup-no-hard-coded-ids` - In a fresh SQLite test database with no rows from migrations or seeders, auto-increment IDs start at 1; use the created rows' IDs
- `setup-one-client-per-test` - A second `tests.New` is another application, which cannot see the first one's rows
- `setup-parallel-tests` - Package variables are shared by parallel tests; keep state on the application

### 4. Database (HIGH)

- `db-assert-the-row-you-changed` - Assert with the row's `id`, and values only this test made
- `db-factory-for-the-acting-user` - `factories.Post` belongs to a new user; pass the owner with `For`
- `db-savepoint-open-is-an-app-bug` - `db.ErrSavepointOpen` in a test means a query ran outside the transaction's `ctx` (`r`, or a goroutine without `db.Concurrent`)

### 5. Background Work (HIGH)

- `bg-attempt-assert-the-effect` - `AssertSucceeded` passes for a job that did nothing; check its effect
- `bg-attempt-retries-and-failed` - `Attempt` runs attempt 1 only and never calls `Failed`; `queuetest.Number` with the last attempt `Tries` allows (a `RetryFor` window is tested by running the worker), and `Failed` called directly or through the worker
- `bg-attempt-retryable` - `AssertFailed` passes for retryable and final failures; check `Retryable`
- `bg-background-errors` - Background work's errors are reported, not returned; `client.AssertNothingReported()`
- `bg-schedule-and-ticks` - Test the schedule with `schedule:run` and time travel; check a tick's `When`

### 6. Time (MEDIUM)

- `time-read-the-app-clock` - Move the clock and compare with `client.Now()`

## Reviewing Laravel for Go Tests

1. **Run the suite twice**: `go test ./...` and `go test -race ./...`; a test that only fails under `-race` or `-count=2` is sharing state (`setup-parallel-tests`)
2. **Search for these patterns.** A match is a place to read, not a finding

| Search for | What to confirm | Rule |
|---|---|---|
| Request tests that dispatch jobs, with no `queuetest.New` | The job's data and `Delay` are asserted on a queue fake | `fake-queue-vs-sync` |
| `queuetest.New`, `mailtest.New` and others after the first `client.Get`/`Post`; helpers that install fakes | Each fake is installed once, before the request | `fake-install-before-the-request` |
| `eventtest.New` with `queuetest.New`; `notificationtest.New` with `mailtest.New` | The assertion's fake is the one the work reaches | `fake-stacked-fakes` |
| `AssertSentTimes[..](0)`, `len(emails.Emails())` in "no email" tests | `AssertNotSent` or `AssertNothingSent` | `fake-mail-sent-vs-queued` |
| `httpclienttest.New`, `processtest.New` | `PreventStrayRequests`/`PreventStrayProcesses`, and `AssertSent`/`AssertRan`; specific patterns first | `fake-http-and-processes-strict` |
| `AssertSentTo` for notifications that must be queued | A match function that checks `Queued` | `fake-notification-queued` |
| `client.Disk(` with no `laraveltest.FakeDisk` | The disk is faked | `fake-disk` |
| `ActingAs` in tests of login, logout, sessions, or middleware that reads the user | A real login through the routes | `http-real-login-vs-acting-as` |
| `ActingAs` on `/api/` routes | `WithToken` with a real token, plus wrong and missing tokens | `http-api-tokens` |
| Authorization tests with one actor; `AssertForbidden()` with no row check | Guest, other user, owner; the row checked after each | `http-authorization-matrix` |
| Routes in `ValidateCSRFToken`'s `Except`; forms that change accounts or money | A cross-site test expecting `419` | `http-csrf-cross-site` |
| `AssertValid()` as the last assertion | The redirect, the landing page and the row | `http-assert-valid-is-not-success` |
| `AssertRedirect(..)` with nothing after it; `Get(protected).AssertOK()` | The landing page's status and content, or `WithoutRedirects` | `http-redirects-are-followed` |
| `AssertJSON`, `AssertJSONFragment`, `AssertJSONMissing(map..)`, `.Etc()` in tests about private fields | `AssertJSONMatches` without `Etc`, `AssertJSONMissingPath`, `AssertExactJSON` | `http-json-exhaustive` |
| `AssertProp` / `AssertPropMissing` for private fields; `Has("..")` | A `Scope` over the object | `http-inertia-scope` |
| Status-only error tests; handlers that call `r.Report` and carry on; hand-written paths | `AssertNothingReported`, `AssertError`, `client.Route` | `http-check-the-error` |
| `"/posts/1"`, `"id": 1`, `== 1` | IDs of the rows the test created | `setup-no-hard-coded-ids` |
| `tests.New` inside helpers, or twice in a test | One client, passed to helpers | `setup-one-client-per-test` |
| Package-level counters or slices read by tests; `t.Parallel()` | State kept on the application | `setup-parallel-tests` |
| `AssertDatabaseHas` without `id`; seeded values in assertions | The row's `id`, and values the test generated | `db-assert-the-row-you-changed` |
| `client.Create(factories.Post)` in tests that act as an owner | `.For("user", owner)` | `db-factory-for-the-acting-user` |
| Tests that expect a `500`, or skip, around `db.ErrSavepointOpen` | The query is fixed to use the callback's `ctx` (or `db.Concurrent` in a goroutine) | `db-savepoint-open-is-an-app-bug` |
| `client.Attempt(..).AssertSucceeded()` with nothing after it | The job's effect is asserted | `bg-attempt-assert-the-effect` |
| Jobs with `Tries` or a `Failed` method tested only with `Attempt(job)` | `queuetest.Number(n)` for the last attempt `Tries` allows (a `RetryFor` window needs the worker); `Failed` checked (called directly, or through the worker when it reads the attempt) | `bg-attempt-retries-and-failed` |
| `AssertFailed`/`AssertFailedWith` on jobs whose retry repeats a side effect | `result.Retryable` checked | `bg-attempt-retryable` |
| Handlers with `r.Background`, tested by status only | `client.AssertNothingReported()` | `bg-background-errors` |
| Scheduled functions called directly; `client.Tick(` | A `schedule:run` test with time travel; the tick's `When` | `bg-schedule-and-ticks` |
| `time.Now()` in tests of stored times | `client.TravelTo` and `client.Now()` | `time-read-the-app-clock` |

3. **Report each finding** with the file and line, how the test can pass while the app is broken (or fail for the wrong reason), the rule, and the test from the rule's Correct example.

## How to Use the Rules

Read individual rule files for the explanation and examples:

```
rules/fake-queue-vs-sync.md
rules/http-real-login-vs-acting-as.md
rules/bg-attempt-assert-the-effect.md
```

Each rule file contains:
- Why it matters, with quotes from the docs (and a few source comments) bundled with `go.laravel.com` v0.2.0
- The common test, as a complete Go file that compiles, and how it passes while the app is broken
- The test to write

## References

- [Laravel for Go](https://laravel.com/go)
- [Laravel for Go testing documentation](https://laravel.com/go/docs/testing)
- [laravel/go skeleton](https://github.com/laravel/go)
- [laravel/go-framework](https://github.com/laravel/go-framework)

## Full Compiled Document

For the complete guide with all rules expanded: `AGENTS.md`

Files in this skill

  • AGENTS.md86.6 KB
  • README.md4.2 KB
  • SKILL.md12.3 KB
  • rules/_sections.md1.2 KB
  • rules/_template.md885 B
  • rules/bg-attempt-assert-the-effect.md2.3 KB
  • rules/bg-attempt-retries-and-failed.md3.9 KB
  • rules/bg-attempt-retryable.md2.9 KB
  • rules/bg-background-errors.md2.7 KB
  • rules/bg-schedule-and-ticks.md3.9 KB
  • rules/db-assert-the-row-you-changed.md2.9 KB
  • rules/db-factory-for-the-acting-user.md2.7 KB
  • rules/db-savepoint-open-is-an-app-bug.md2.9 KB
  • rules/fake-disk.md2.5 KB
  • rules/fake-http-and-processes-strict.md4 KB
  • rules/fake-install-before-the-request.md3.2 KB
  • rules/fake-mail-sent-vs-queued.md2.8 KB
  • rules/fake-notification-queued.md2.9 KB
  • rules/fake-queue-vs-sync.md3.9 KB

Attribution

Is this your skill, or is something wrong with this listing? Request removal or report an issue. Author removals are honored within 72 hours.

View all in databases →

Comments

Loading comments…

Newsletter

Get the weekly list of safe new skills, and the ones we pulled.