Laravel feature and unit tests, with a real app
What feature and unit tests mean in Laravel, worked through on a real invoicing app: pure domain classes, HTTP flows, fakes and the clock, factories and CI, and a real browser. Six parts on Laravel 13 and Pest 5, every test run.
By Abhishek Fouzdar · Updated
Most testing tutorials test a calculator. Real applications have a database, a queue, mail, a payment provider, a cron job and a browser, and the hard questions about testing only show up there: what is a unit test when the model needs the database, how do you test a webhook that only the provider can send, what do you do about the clock, and when is a browser test worth its weight. This series answers those questions on a real app, built from laravel new to a green CI in six parts, with every test run and every output shown. Laravel 13, Pest 5, PHP 8.5, on 24 October 2026.
The app is InvoiceMini. A company's users create invoices for clients, send them, and get paid: a sent invoice gets a number and a due date, a PDF goes to the client from a queue, a signed webhook from the payment provider records the money and triggers a receipt, overdue invoices get a reminder every morning, and totals in another currency are shown at today's rate. Small enough to read in an evening, built from the parts that make testing hard.

Who this is for
You write Laravel and you have written some tests, probably feature tests that post to a route and check the database. You are not sure when to write a unit test instead, your suite has a few tests that only pass on Tuesdays, and something in it is slow. Every assertion in the series is explained the first time it appears, and every part ends with what went wrong while writing it, because the mistakes are where the understanding is.
What you will end up with
A public repository, shipbytes/laravel-testing-guide, with one commit per part, 128 tests that run in twelve seconds on a laptop, and a GitHub Actions workflow that runs them on two PHP versions, against MySQL, and in a real browser.
| Layer | What it tests in InvoiceMini |
|---|---|
| Unit | Invoice totals with per-line tax and rounding, invoice numbering, due dates with weekend roll, money formatting per currency. Plain PHP, no container, no database. |
| Feature | Login, the invoice form and its validation, policies, sending with sequential numbers, the payment webhook, the delivery job, the reminder command, exchange rates. |
| Browser | Chromium through Playwright: the login form, the invoice form with its add-and-remove-line script, validation errors on the page, and a smoke test for script errors and accessibility. |
The parts
- What feature and unit mean in Laravel, and the foundation. A fresh app with Pest, the test configuration the installer wrote, the domain's tables and models, a hand-written login, and the first twenty tests.
- Unit tests on the billing domain. Totals, numbering, due dates and money as pure classes, tested with datasets and fixed dates. Where the line between unit and feature really sits.
- Feature tests on the invoice flows. Create, edit, send, void and delete over HTTP: validation datasets, policies, a form request that authorises before it validates, frozen time, and a number sequence that survives 9999.
- Fakes and time. A signed payment webhook, a queued listener that mails a receipt, a job that renders a PDF and mails it, exchange rates over HTTP, and a reminder command on the scheduler. Mail, Bus, Event, Storage, Http and Notification fakes, and the clock.
- Database, factories, speed and CI. Architecture tests that keep the domain pure, factory techniques that keep tests short, SQLite against MySQL, parallel runs, coverage, type coverage, and the workflow.
- Browser tests. Pest's browser plugin on Playwright: driving the form, screenshots, traces, and running it in GitHub Actions.
What you need
- PHP 8.4 or later, Composer, Node 20 or later. Pest 5 needs PHP 8.4; the series used PHP 8.5.4 and Node 24.
- Docker, only for part 5's run against MySQL. Optional.
- About 300 MB of disk for Playwright's Chromium in part 6.
- An evening for parts 1 to 3 and another for 4 to 6.
A note on the tools
Pest 5 came out in July 2026 on PHPUnit 13. Everything here is Pest syntax, but every assertion is a PHPUnit assertion underneath and the Laravel testing helpers are the same whichever you use; part 1 shows the PHPUnit form of a test once so nothing is lost in translation. Laravel 13 ships Pest as its default when you ask for it, writes #[Fillable] attributes on models instead of $fillable properties, and includes a small package that prints test results as JSON when it detects an AI coding agent. That last one caught me on the first run; part 1 explains.
Start with part 1. When you are done, InvoiceMini carries on: the Claude API series forks this app and gives it an invoice drafter, a streamed reminder, an assistant over its data and a monthly summary, with the same testing discipline and an eval on top.
New posts by email
Get new posts by email. Nothing else, no digests, unsubscribe in one click.
Comments
Comments are GitHub Discussions in shipbytes/discussions. Sign in with GitHub to post.
In this series
6 parts