title: Full Testing Guide description: Unit, feature, mock, and end-to-end testing with Testbench.
Full Testing Guide
Guardrails is tested with Pest + Orchestra Testbench using an in-memory sqlite database. This guide explains how to run the suite and how to test your app-specific flows.
Running the Suite
composer update
./vendor/bin/pest --coverage
What’s Covered
- Unit tests: builder, signing policy, auth helper.
- Feature tests: route registration, capture via trait, approve via API, controller interceptor.
- Events: faked and asserted for capture and completion.
Structure
- Tests use a stub
users
provider model and aposts
table. - Guard is set to
web
for simplicity in tests; the package uses your configured guard.
Writing Your App Tests
- Use in-memory sqlite or test DB; load Guardrails migrations and your own tables.
- Create a model with the
Guardrail
trait and declare guarded attributes. actingAs($user, config('guardrails.auth.guard'))
to test capture/approve flows.- Event testing:
Event::fake([...])
andEvent::assertDispatched(...)
.
CI
GitHub Actions workflow run-tests.yml
runs the suite across PHP 8.1–8.3 and uploads coverage to Codecov.
Related Guides
- Model Guarding Guide — Set up fixtures that mirror your production models.
- Controller Interception Guide — Cover interceptor flows in feature tests.
- Advanced Flows — Know what behaviours to assert for dynamic policies.
- Common Patterns — Use sample flows as starting points for new specs.