pestphp/pest-plugin-laravel
Pest Plugin for Laravel adds Laravel-specific testing helpers and integration to Pest, making it easy to write expressive, fast tests for Laravel apps while leveraging the familiar Laravel testing ecosystem.
Install Pest and the Laravel plugin via Composer:
composer require --dev pestphp/pest pestphp/pest-plugin-laravel
Run php artisan test:make --pest to generate Pest-style tests (e.g., tests/Feature/UserTest.php). Begin with simple feature tests using Laravel’s built-in testing helpers — the plugin auto-registers Laravel’s test traits like RefreshDatabase, WithoutMiddleware, and InteractsWithAuthentication by default. Your first test might look like:
it('shows the homepage', function () {
$response = $this->get('/');
$response->assertStatus(200);
});
Check phpunit.xml — the plugin populates this with Pest configuration, and tests live in tests/ with Feature and Unit subdirectories.
actingAs(), getJson(), postJson(), refreshDatabase(), and assertions like assertJsonPath() directly. The plugin patches these via TestCase enhancements.Database\Factories — call User::factory()->create() and chain database assertions.parallel in phpunit.xml, the plugin intelligently handles database isolation using per-process databases (requires RefreshDatabase and parallel support).make:test command with custom stubs in stubs/test.php — it respects Laravel conventions (e.g., test_create_user → UserTest.php).it(), test(), and describe() blocks with Laravel’s testing context — e.g.:describe('user registration', function () {
beforeEach(fn () => $this->withoutMiddleware());
it('creates a new user', function () {
$user = User::factory()->make();
$this->post('/register', $user->toArray());
$this->assertDatabaseHas('users', ['email' => $user->email]);
});
});
TestCase directly — Pest tests should extend Pest\Laravel\TestCase implicitly. Don’t manually use TestCase; let Pest handle it.$this->withoutMiddleware() or $this->withMiddleware() explicitly — forgetting this causes 302 redirects instead of 200.RefreshDatabase is great, but for large suites, consider DatabaseTransactions for speed (especially in unit tests where full isolation isn’t needed)..env.testing, but php artisan test now respects --env and .env.test — ensure your test .env is configured (e.g., DB_CONNECTION=sqlite, DB_DATABASE=:memory:).Pest\Laravel\ServiceProvider if you need to override default behaviors or add custom macros. contributed to by laravel-tests, not the core Pest package, so keep both updated.How can I help you explore Laravel packages today?