Keploy logo
Laravel logo

Keploy as a Laravel testing framework

Keploy tests Laravel applications by recording real requests through the running server and every Eloquent query or HTTP client call they trigger, then replaying both as assertions. RefreshDatabase never runs, because there is no test database to migrate.

Generate Laravel tests free
keploy record -c "php artisan serve --port=8000"
18.4K+VS Code1.2M+300M+mocks created

What Keploy gives a Laravel team

Any Laravel app, unchanged

Keploy runs the app through artisan serve, Octane, or PHP-FPM. Route middleware, form request validation, and service providers all execute because capture happens at the socket.

  • Laravel 9 and above
  • artisan serve, Octane, or FPM
  • API and web routes
  • Providers boot for real
The problem

Why Laravel integration tests slow teams down

The friction is rarely the assertions. It is everything around them — spinning up dependencies, keeping mocks honest, and repairing tests after every refactor.

Three ways to do it

Testing Laravel: by hand, with PHPUnit + Http::fake, or with Keploy

Http::fake and RefreshDatabase buy convenience with a frozen upstream contract and a migration run per suite. Keploy records the real exchanges instead, so neither cost is paid.

Select any row for the full comparison, with code.

Same coverage, three costs

What you write for Laravel vs what Keploy records

All three produce the same assertion. Only the third still passes after the next refactor without anyone editing it.

By hand2–4 hours
OrderControllerTest.php
hand-written
<?php
// Hand-written: a repository stub bound into the container.
use Tests\TestCase;
 
final class OrderControllerTest extends TestCase
{
public function test_confirms_an_authorized_order(): void
{
$this->app->bind(OrderRepository::class, fn () => new class implements OrderRepository {
public function find(string $id): array
{
return ['id' => $id, 'amount_minor' => 4200, 'state' => 'NEW'];
}
});
 
$response = $this->postJson('/api/orders/ord_1/confirm', [
'payment_token' => 'tok_123',
]);
 
$response->assertOk()->assertJsonPath('state', 'CONFIRMED');
}
}

An anonymous class bound into the container for one test. It hard-codes a row shape that nothing checks against the real orders table.

PHPUnit + Http::fake1–2 hours
OrderControllerFakeTest.php
tool-assisted
<?php
// PHPUnit + Http::fake + RefreshDatabase.
use Illuminate\Foundation\Testing\RefreshDatabase;
use Illuminate\Support\Facades\Http;
use Tests\TestCase;
 
final class OrderControllerFakeTest extends TestCase
{
use RefreshDatabase;
 
public function test_confirms_an_authorized_order(): void
{
Order::factory()->create(['id' => 'ord_1', 'amount_minor' => 4200]);
 
// A literal that will not change when Stripe does.
Http::fake([
'api.payments.example.com/*' => Http::response(['status' => 'AUTHORIZED'], 200),
]);
 
$response = $this->postJson('/api/orders/ord_1/confirm', [
'payment_token' => 'tok_123',
]);
 
$response->assertOk()->assertJsonPath('state', 'CONFIRMED');
Http::assertSent(fn ($r) => str_contains($r->url(), 'tok_123'));
}
}

Expressive and idiomatic — and it needs a migrated test database, a factory, and a Stripe body typed out by hand.

With Keploy~5 minutes
test-1.yaml
auto-generated
# Recorded with: keploy record -c 'php artisan serve --port=8000'
# No RefreshDatabase. No factory. No Http::fake.
version: api.keploy.io/v1beta1
kind: Http
name: test-1
spec:
req:
method: POST
url: /api/orders/ord_1/confirm
header:
Authorization: Bearer <captured>
body: '{"payment_token":"tok_123"}'
resp:
status_code: 200
body:
id: "ord_1"
state: "CONFIRMED"
amount_minor: 4200
confirmed_at: "2026-09-02T11:04:18Z"
noise:
- body.confirmed_at
mocks:
- kind: MySQL
operation: "select * from `orders` where `orders`.`id` = ? limit 1"
- kind: Http
url: https://api.payments.example.com/v1/payment_intents/tok_123/confirm
status: 200

The mock is the SQL Eloquent actually compiled, backticks and all, so a scope or relation change shows up as a diff rather than passing against a factory record.

Times are estimates for authoring one endpoint’s coverage from scratch, not measurements.

Keploy vs the alternatives

Laravel testing tools, compared

The options a team on PHP actually reaches for, and where each one genuinely wins. Select a row for the full comparison.

Best in classStrongPartialNot covered

Assessments reflect each tool’s documented behaviour, not benchmark measurements.

How it works

Record your Laravel app once, replay it forever

Keploy sits below your Laravel process at the network layer. It watches the calls your app already makes, then serves them back on replay so tests run with no dependencies attached.

Keploy records a GET call to /api/v1/orders/{id} on a Laravel service and captures the dependency calls it makes.

An example shape of a captured call. Your own endpoints and dependencies come from your real traffic, so nothing here has to be written by hand.
Mock coverage

What Keploy mocks for Laravel, with zero config

5 of the 6 dependencies a typical Laravel service talks to are stubbed from the recording itself — no mock classes, no fixture files, no containers in CI.

Quick start

Your first Laravel test suite in under five minutes

Every command below runs against your existing Laravel service. Nothing in your source tree changes.

  1. 1Install the Keploy CLI

    A single binary. It needs a Linux kernel with eBPF support, or Docker on macOS and Windows — and it adds nothing to your project's dependencies.

    curl -sSL https://keploy.io/install.sh | bash
  2. 2Record your service

    Pass the command you already use to start the app. Keploy runs it and watches every socket it opens.

    keploy record -c "php artisan serve --port=8000"
  3. 3Exercise the paths you care about

    Drive the running app. Every request becomes a test case with its Eloquent queries and HTTP client calls captured alongside.

    curl -X POST localhost:8000/api/orders/ord_1/confirm -H 'Content-Type: application/json' -H 'Authorization: Bearer $TOKEN' -d '{"payment_token":"tok_123"}'
  4. 4Replay in CI

    Replay serves the recorded dependency responses, so the job needs no service containers and no Docker daemon.

    keploy test -c "php artisan serve --port=8000" --delay 8

Ready to try it on your own Laravel service?

Ecosystem

Works with the rest of your Laravel stack

Keploy records at the network layer, so framework and driver choices inside your Laravel app do not change how it captures traffic.

FAQ

Laravel testing with Keploy: common questions

Join our GlobalCommunity

Connect with developers worldwide. Follow updates, ask questions, share feedback, and ship faster with other Keploy builders.

1.2M+Installs
18.4K+GitHub
100K+Devs
300M+Mocks
1K+Contributors
#1OSS Trending
4.9★★★★★from 500+ reviews onG2GartnerVS CodeChrome
★★★★★

Best report of integration and API tests I've seen — which we don't get from RestAssured.

G2
★★★★★

Future of microservices testing. I don't write tests now!

G2 · 5/5
★★★★★

An amazing product that simplifies the automation.

Gartner · 4.0
XGitHubSlackYouTubeLinkedIn
Built by developers, for developers.Let's build the future, together.