PHPackages                             shiishiji/wiremock-php - 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. [API Development](/categories/api)
4. /
5. shiishiji/wiremock-php

ActiveLibrary[API Development](/categories/api)

shiishiji/wiremock-php
======================

PHP API for WireMock JSON interface

2.33.1(3y ago)03MITPHPPHP &gt;=8.0

Since Dec 1Pushed 3y agoCompare

[ Source](https://github.com/Shiishiji/wiremock-php)[ Packagist](https://packagist.org/packages/shiishiji/wiremock-php)[ Docs](http://github.com/rowanhill/wiremock-php)[ RSS](/packages/shiishiji-wiremock-php/feed)WikiDiscussions master Synced 1mo ago

READMEChangelog (1)Dependencies (6)Versions (21)Used By (0)

wiremock-php [![Build Status](https://camo.githubusercontent.com/f5f08be568446af49873afd9b5512f6cf2c21ba96b57e6681fe44d839123922b/68747470733a2f2f7472617669732d63692e6f72672f726f77616e68696c6c2f776972656d6f636b2d7068702e706e673f6272616e63683d6d6173746572)](https://travis-ci.org/rowanhill/wiremock-php)
==============================================================================================================================================================================================================================================================================================================

[](#wiremock-php-)

**Stub and mock web services with the power of [WireMock](https://github.com/tomakehurst/wiremock) from PHP.**

WireMock provides a JSON API for interacting with it; wiremock-php makes it easy to use that JSON API from PHP by wrapping it up in a fluent API very similar to the Java API provided by WireMock.

Note that wiremock-php requires a standalone instance of WireMock to be run (which requires Java).

Version numbers track those of WireMock itself, but may lag behind (i.e. if a WireMock release does not contain changes to the API, there may be no corresponding version of wiremock-php).

Alternatives
------------

[](#alternatives)

Like the idea of stubbing &amp; verifying HTTP requests, but don't like this library (maybe you don't want to install Java)? You might want to investigate the following:

- [http-mock](https://github.com/InterNations/http-mock)
- [mock-http-server](https://github.com/cepa/mock-http-server)

Installation
------------

[](#installation)

It's easiest to install wiremock-php via Composer:

```
php composer.phar require --dev shiishiji/wiremock-php:2.33.1
```

Usage
-----

[](#usage)

### API

[](#api)

The API is based directly on WireMock's Java API, so see the [WireMock documentation](http://wiremock.org/) for general help with interacting with WireMock.

### Differences to Java API

[](#differences-to-java-api)

To provide a fluent interface, the WireMock Java API makes use of statically imported methods (which act upon a default static instance), but it's also possible to act directly upon a Java WireMock instance (using slightly differently named methods).

Prior to version 5.6 (back when wiremock-php was created), PHP didn't support anything like Java's static import of methods. Instead, in wiremock-php some methods which are static in Java are instance methods. Those methods are:

- `stubFor`, `editStub`, `importStubs`
- `verify`
- `get`, `post`, `put`, `delete`, `patch`, `head`, `options`, `trace`, `any`
- all the various matcher methods
- `getAllServeEvents`, `findAll`, `findUnmatchedRequests`, `findNearMissesFor`, `findNearMissesForAllUnmatched`
- `listAllStubMappings`, `getSingleStubMapping`, `findStubsByMetadata`, `removeStubsByMetadata`
- `saveAllMappings`
- `reset`, `resetToDefault`
- `resetAllRequests`, `removeServeEvent`, `removeServeEvents`, `removeEventsByStubMetadata`
- `getAllScenarios`, `resetAllScenarios`, `resetScenario`, `setScenarioState`
- `setGlobalFixedDelay`, `setGlobalRandomDelay`, `resetGlobalDelays`
- `startRecording`, `getRecordingStatus`, `stopRecording`, `snapshotRecord`
- `shutdownServer`

Also, the Java API has methods (`ResponseDefinitionBuilder::withBody` and `WebhookDefinition::withBinaryBody`) that take a byte array. Byte arrays are less common in PHP, so instead, `withBodyData` methods are provided, which takes a string to be base64 encoded. To produce an appropriate string from an array of bytes, use [pack](http://php.net/pack).

The date and time request matcher functions (`before`, `beforeNow`, `equalToDateTime`, `isNow`, `after`, `afterNow`) can be used with offsets (`expectedOffset($amount, $unit)`). In the Java API, the unit parameter is an enum; in wiremock-php these values are consts on `DateTimeMatchingStrategy`. Similarly, truncation types (for use with `truncateExpected` and `truncateActual`) are enums in the Java API, but are consts on `DateTimeMatchingStrategy` in wiremock-php.

The `stubImport` method is static on `StubBuilder` in Java. In WireMock, to keep all the public static methods in one predictable place, this method is available as `WireMock::stubImport`.

The request method constants are available on `WireMock\Http\RequestMethod`;

In addition, wiremock-php adds the instance method `isAlive`. This polls the standalone WireMock instance until an OK response is received or a timeout is reached, allowing your PHP code to wait until WireMock is ready.

### Example

[](#example)

A typical usage looks something like the following:

```
// Create an object to administer a WireMock instance. This is assumed to be at
// localhost:8080 unless these values are overridden.
$wireMock = WireMock::create(/* specify host, port here if needed */);

// Assert that the standalone service is running (by waiting for it to respond
// to a request within a timeout)
assertThat($wireMock->isAlive(), is(true));

// Stub out a request
$wireMock->stubFor(WireMock::get(WireMock::urlEqualTo('/some/url'))
    ->willReturn(WireMock::aResponse()
        ->withHeader('Content-Type', 'text/plain')
        ->withBody('Hello world!')));

// ... interact with the server ...

// Verify a request
$wireMock->verify(WireMock::postRequestedFor(WireMock::urlEqualTo('/verify/this'))
    ->withHeader('Content-Type', WireMock::equalTo('text/xml')));
```

### Verification PHPUnit integration

[](#verification-phpunit-integration)

If a verification fails a `VerificationException` is thrown. If PHPUnit is present on the include path, this will be a subclass of `PHPUnit_Framework_AssertionFailedError`, thus causing any containing PHPUnit test to fail; if PHPUnit is not present, `VerificationException` subclasses `Exception`.

###  Health Score

30

—

LowBetter than 64% of packages

Maintenance20

Infrequent updates — may be unmaintained

Popularity3

Limited adoption so far

Community9

Small or concentrated contributor base

Maturity77

Established project with proven stability

 Bus Factor1

Top contributor holds 95.3% 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 ~183 days

Recently: every ~42 days

Total

18

Last Release

1431d ago

Major Versions

0.2.0 → 1.392013-12-27

1.43.2 → 2.182018-06-10

PHP version history (2 changes)2.33.0PHP &gt;=7.2

2.33.1PHP &gt;=8.0

### Community

Maintainers

![](https://www.gravatar.com/avatar/192b8afcf69aedd10f6ca1c6f60ace25f41130d7e6a7928b577fd57653bb5196?d=identicon)[Shiishiji](/maintainers/Shiishiji)

---

Top Contributors

[![rowanhill](https://avatars.githubusercontent.com/u/2607287?v=4)](https://github.com/rowanhill "rowanhill (204 commits)")[![OndraM](https://avatars.githubusercontent.com/u/793041?v=4)](https://github.com/OndraM "OndraM (6 commits)")[![miguelsimoes](https://avatars.githubusercontent.com/u/4938185?v=4)](https://github.com/miguelsimoes "miguelsimoes (4 commits)")

###  Code Quality

TestsPHPUnit

### Embed Badge

![Health badge](/badges/shiishiji-wiremock-php/health.svg)

```
[![Health](https://phpackages.com/badges/shiishiji-wiremock-php/health.svg)](https://phpackages.com/packages/shiishiji-wiremock-php)
```

###  Alternatives

[sylius/sylius

E-Commerce platform for PHP, based on Symfony framework.

8.4k5.6M651](/packages/sylius-sylius)[api-platform/symfony

Symfony API Platform integration

323.2M67](/packages/api-platform-symfony)[api-platform/serializer

API Platform core Serializer

223.4M31](/packages/api-platform-serializer)[fschmtt/keycloak-rest-api-client-php

PHP client to interact with Keycloak's Admin REST API.

4684.7k2](/packages/fschmtt-keycloak-rest-api-client-php)

PHPackages © 2026

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