Keploy logo
PHP logo

Keploy as a PHP testing framework

Keploy tests PHP applications by recording real HTTP and PDO traffic from a running app, then replaying it as assertions. There are no Guzzle MockHandler queues to build, no PHPUnit doubles to configure, and no test database to migrate before the suite runs.

Generate PHP tests free
keploy record -c "php -S 0.0.0.0:8000 -t public"
18.4K+VS Code1.2M+300M+mocks created

What Keploy gives a PHP team

Any PHP app, unchanged

Keploy runs the app through the built-in server, PHP-FPM, or FrankenPHP. Laravel, Symfony, Slim, and plain PSR-15 stacks all record the same way because capture happens at the socket.

  • PHP 8.0 and above
  • Built-in server, FPM, or FrankenPHP
  • Laravel, Symfony, Slim, Laminas
  • No test bootstrap changes
The problem

Why PHP 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 PHP: by hand, with PHPUnit + Guzzle MockHandler, or with Keploy

PHPUnit doubles and a MockHandler queue are both written from your model of a dependency. Keploy records what the dependency actually returned, so re-recording refreshes every mock at once.

Select any row for the full comparison, with code.

Same coverage, three costs

What you write for PHP 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: stubs and payloads all by hand.
use PHPUnit\Framework\TestCase;
 
final class FakeOrderRepository implements OrderRepository
{
public function find(string $id): array
{
return ['id' => $id, 'amount_minor' => 4200, 'state' => 'NEW'];
}
}
 
final class OrderControllerTest extends TestCase
{
public function testConfirmsAnAuthorizedOrder(): void
{
$controller = new OrderController(
new FakeOrderRepository(),
new FakePaymentClient('AUTHORIZED'),
);
 
$response = $controller->confirm('ord_1', 'tok_123');
 
self::assertSame(200, $response->getStatusCode());
}
}

Two stub classes exist only for this file, and both hard-code a shape nothing verifies against the real MySQL rows or Stripe response.

PHPUnit + Guzzle MockHandler1–2 hours
OrderControllerMockTest.php
tool-assisted
<?php
// PHPUnit + Guzzle MockHandler.
use GuzzleHttp\Handler\MockHandler;
use GuzzleHttp\Psr7\Response;
use PHPUnit\Framework\TestCase;
 
final class OrderControllerMockTest extends TestCase
{
public function testConfirmsAnAuthorizedOrder(): void
{
// Order-dependent: add a call and this queue breaks.
$mock = new MockHandler([
new Response(200, [], '{"status":"AUTHORIZED"}'),
]);
 
$repo = $this->createMock(OrderRepository::class);
$repo->method('find')->willReturn([
'id' => 'ord_1', 'amount_minor' => 4200, 'state' => 'NEW',
]);
 
$controller = new OrderController($repo, new Payments($mock));
$response = $controller->confirm('ord_1', 'tok_123');
 
self::assertSame(200, $response->getStatusCode());
}
}

Fast and dependency-free — and the Stripe body is a literal, while the queue itself couples the test to how many calls the code happens to make.

With Keploy~5 minutes
test-1.yaml
auto-generated
# Recorded with: keploy record -c 'php -S 0.0.0.0:8000 -t public'
# No MockHandler queue, no doubles, no test schema.
version: api.keploy.io/v1beta1
kind: Http
name: test-1
spec:
req:
method: POST
url: /orders/ord_1/confirm
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 id, amount_minor, state FROM orders WHERE id = ?"
- kind: Http
url: https://api.payments.example.com/v1/payment_intents/tok_123/confirm
status: 200

Mocks are matched to the call that produced them rather than queued in order, so adding an unrelated request does not break the recorded case.

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

Keploy vs the alternatives

PHP 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 PHP app once, replay it forever

Keploy sits below your PHP 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 PHP 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 PHP, with zero config

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

Quick start

Your first PHP test suite in under five minutes

Every command below runs against your existing PHP 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 -S 0.0.0.0:8000 -t public"
  3. 3Exercise the paths you care about

    Drive the app with curl or your frontend. Every request becomes a test case with its PDO queries and Guzzle calls captured alongside.

    curl -X POST localhost:8000/orders/ord_1/confirm -H 'Content-Type: application/json' -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 -S 0.0.0.0:8000 -t public" --delay 8

Ready to try it on your own PHP service?

Ecosystem

Works with the rest of your PHP stack

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

FAQ

PHP 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.