Packagist
Packagist 
The mock-server/mockserver-client package provides a PHP client for MockServer's control-plane REST API, with a fluent builder API covering expectations, verification, retrieval, and control operations. PHP 8.1+ and Composer are required.
Install
composer require mock-server/mockserver-client
Quick start
<?php
use MockServer\MockServerClient;
use MockServer\HttpRequest;
use MockServer\HttpResponse;
use MockServer\VerificationTimes;
// Connect to MockServer
$client = new MockServerClient('localhost', 1080);
// Create an expectation
$client->when(
HttpRequest::request()->method('GET')->path('/hello')
)->respond(
HttpResponse::response()
->statusCode(200)
->header('Content-Type', 'application/json')
->body('{"message":"world"}')
);
// Verify the request was received
$client->verify(
HttpRequest::request()->path('/hello'),
VerificationTimes::atLeast(1)
);
// Reset
$client->reset();
Starting MockServer
The PHP client does not include a binary launcher. To start MockServer, use one of these approaches:
- Docker:
docker run -d -p 1080:1080 mockserver/mockserver - Another client's launcher: the Python, Ruby, Go, .NET, and Rust clients can each download and start MockServer automatically — see Running MockServer — client library launcher.
- Executable JAR / Homebrew: see Downloads and Homebrew.
For the full PHP client API, see MockServer clients.