Testing Summary
PHP testing with PHPUnit/Pest covers unit tests (isolated logic), feature tests (full HTTP stack), database tests (factories + RefreshDatabase), and mocking (Http::fake, Mail::fake, Queue::fake). Run in CI on every push.
PHP testing with PHPUnit/Pest covers unit tests (isolated logic), feature tests (full HTTP stack), database tests (factories + RefreshDatabase), and mocking (Http::fake, Mail::fake, Queue::fake). Run in CI on every push.
# Complete test workflow
composer require --dev pestphp/pest
./vendor/bin/pest --parallel --coverage --min=70
# CI: run on every PR (GitHub Actions)
- run: ./vendor/bin/pest --parallel --ci
# Key patterns summary:
# Unit test → TestCase, no DB, mock dependencies
# Feature test → RefreshDatabase, actingAs, postJson
# Data-driven → it()->with(dataset)
# Fakes → Http::fake(), Mail::fake(), Event::fake()
A test suite that runs in under 30 seconds gets run — a slow suite gets skipped.
This is the last lesson in this section.
Create a free account to earn a certificate