PHPackages                             mock-server/mockserver-testcontainers - PHPackages - PHPackages  [Skip to content](#main-content)[PHPackages](/)[Directory](/)[Categories](/categories)[Trending](/trending)[Leaderboard](/leaderboard)[Changelog](/changelog)[Analyze](/analyze)[Collections](/collections)[Log in](/login)[Sign up](/register)

1. [Directory](/)
2. /
3. [Testing &amp; Quality](/categories/testing)
4. /
5. mock-server/mockserver-testcontainers

ActiveLibrary[Testing &amp; Quality](/categories/testing)

mock-server/mockserver-testcontainers
=====================================

Testcontainers module for MockServer — starts a mockserver/mockserver Docker container, waits for readiness, and exposes connection helpers plus a ready-wired MockServer client.

7.5.0(1mo ago)00Apache-2.0PHPPHP &gt;=8.1

Since Jul 4Pushed 1mo agoCompare

[ Source](https://github.com/mock-server/mockserver-testcontainers-php)[ Packagist](https://packagist.org/packages/mock-server/mockserver-testcontainers)[ Docs](https://www.mock-server.com)[ RSS](/packages/mock-server-mockserver-testcontainers/feed)WikiDiscussions master Synced 1w ago

READMEChangelogDependencies (6)Versions (3)Used By (0)

mockserver-testcontainers (PHP)
===============================

[](#mockserver-testcontainers-php)

A [Testcontainers](https://github.com/testcontainers/testcontainers-php) module for [MockServer](https://www.mock-server.com) — the open-source HTTP(S) mock server and proxy.

It starts the official `mockserver/mockserver` Docker image, waits for MockServer to become ready (`PUT /mockserver/status` → `200`), and exposes connection helpers plus a ready-wired [`mock-server/mockserver-client`](https://packagist.org/packages/mock-server/mockserver-client)instance.

Install
-------

[](#install)

```
composer require --dev mock-server/mockserver-testcontainers
```

Requires PHP &gt;= 8.1 and a running Docker daemon.

Usage
-----

[](#usage)

```
use MockServer\Testcontainers\MockServerContainer;
use MockServer\HttpRequest;
use MockServer\HttpResponse;

$container = (new MockServerContainer())->start();

// A ready-wired MockServer client pointed at the mapped host/port.
// (getMockServerClient() is the PHP analogue of Java's getClient() — the
// inherited getClient() name is reserved by Testcontainers for the Docker client.)
$client = $container->getMockServerClient();
$client
    ->when(HttpRequest::request()->method('GET')->path('/hello'))
    ->respond(HttpResponse::response()->statusCode(200)->body('world'));

// Point the system under test at the container endpoint
$container->getEndpoint();        // "http://localhost:49152"
$container->getSecureEndpoint();  // "https://localhost:49152" (HTTP/HTTPS share the port)

$container->stop();
```

By default the image tag is derived from the installed MockServer PHP client version (`mockserver/mockserver:mockserver-`), so the container and client always match. It falls back to `:latest` when the version cannot be resolved to a release version. Pass an explicit image to pin it:

```
new MockServerContainer('mockserver/mockserver:mockserver-7.4.0');
```

Configuration helpers
---------------------

[](#configuration-helpers)

Each returns the container for chaining, and must be called before `start()`.

MethodWhat it does`withServerPort(int)`Change the port MockServer listens on inside the container.`withLogLevel(string)`Set `MOCKSERVER_LOG_LEVEL` (e.g. `"DEBUG"`).`withMockServerProperty(string, string)`Set any MockServer configuration property by its env-var name.`withInitializationJson(string)`Copy a JSON file into the container and load its expectations at startup.Standard Testcontainers `GenericContainer` helpers (`withNetwork`, `withEnvironment`, `withExposedPorts`, …) are also available via inheritance.

Connection helpers (on the started container)
---------------------------------------------

[](#connection-helpers-on-the-started-container)

MethodReturns`getMockServerClient()`A cached `MockServer\MockServerClient` connected to the container.`getEndpoint()``http://host:port``getSecureEndpoint()``https://host:port` (same unified port)`getServerPort()`The mapped host port.`getHost()`The host MockServer is reachable on.License
-------

[](#license)

Apache-2.0

###  Health Score

37

—

LowBetter than 81% of packages

Maintenance91

Actively maintained with recent releases

Popularity0

Limited adoption so far

Community6

Small or concentrated contributor base

Maturity43

Maturing project, gaining track record

 Bus Factor1

Top contributor holds 100% of commits — single point of failure

How is this calculated?**Maintenance (25%)** — Last commit recency, latest release date, and issue-to-star ratio. Uses a 2-year decay window.

**Popularity (30%)** — Total and monthly downloads, GitHub stars, and forks. Logarithmic scaling prevents top-heavy scores.

**Community (15%)** — Contributors, dependents, forks, watchers, and maintainers. Measures real ecosystem engagement.

**Maturity (30%)** — Project age, version count, PHP version support, and release stability.

###  Release Activity

Cadence

Every ~0 days

Total

2

Last Release

46d ago

### Community

Maintainers

![](https://avatars.githubusercontent.com/u/733179?v=4)[James D Bloom](/maintainers/jamesdbloom)[@jamesdbloom](https://github.com/jamesdbloom)

---

Top Contributors

[![jamesdbloom](https://avatars.githubusercontent.com/u/733179?v=4)](https://github.com/jamesdbloom "jamesdbloom (2 commits)")

---

Tags

httptestingmockdockerintegration-testingtestcontainersmockserver

###  Code Quality

TestsPHPUnit

### Embed Badge

![Health badge](/badges/mock-server-mockserver-testcontainers/health.svg)

```
[![Health](https://phpackages.com/badges/mock-server-mockserver-testcontainers/health.svg)](https://phpackages.com/packages/mock-server-mockserver-testcontainers)
```

###  Alternatives

[mockery/mockery

Mockery is a simple yet flexible PHP mock object framework

10.7k536.9M28.6k](/packages/mockery-mockery)[donatj/mock-webserver

Simple mock web server for unit testing

1392.7M102](/packages/donatj-mock-webserver)[php-mock/php-mock

PHP-Mock can mock built-in PHP functions (e.g. time()). PHP-Mock relies on PHP's namespace fallback policy. No further extension is needed.

37020.4M140](/packages/php-mock-php-mock)[phake/phake

The Phake mock testing library

4858.3M356](/packages/phake-phake)[brain/monkey

Mocking utility for PHP functions and WordPress plugin API

34315.0M591](/packages/brain-monkey)[kahlan/kahlan

The PHP Test Framework for Freedom, Truth and Justice.

1.1k1.3M262](/packages/kahlan-kahlan)

PHPackages © 2026

[Directory](/)[Categories](/categories)[Trending](/trending)[Changelog](/changelog)[Analyze](/analyze)
