PHPackages                             wiremock-php/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. wiremock-php/wiremock-php

ActiveLibrary[API Development](/categories/api)

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

PHP API for WireMock JSON interface

2.35.4(2mo ago)901.5M—9.4%15[4 PRs](https://github.com/rowanhill/wiremock-php/pulls)19MITPHPPHP &gt;=7.2CI passing

Since Dec 1Pushed 2mo ago2 watchersCompare

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

READMEChangelog (10)Dependencies (10)Versions (29)Used By (19)

wiremock-php [![CircleCI](https://camo.githubusercontent.com/e54002513f8a2c26e7f8c05c74fcd8f0cfeab6c4c1cde1b57ad4dd3d5c093f05/68747470733a2f2f646c2e636972636c6563692e636f6d2f7374617475732d62616467652f696d672f67682f726f77616e68696c6c2f776972656d6f636b2d7068702f747265652f6d61737465722e7376673f7374796c653d736869656c64)](https://dl.circleci.com/status-badge/redirect/gh/rowanhill/wiremock-php/tree/master)
===================================================================================================================================================================================================================================================================================================================================================================================================================

[](#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 wiremock-php/wiremock-php:2.35.3
```

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

62

—

FairBetter than 99% of packages

Maintenance84

Actively maintained with recent releases

Popularity55

Moderate usage in the ecosystem

Community28

Small or concentrated contributor base

Maturity69

Established project with proven stability

 Bus Factor1

Top contributor holds 95% 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 ~203 days

Recently: every ~299 days

Total

23

Last Release

80d ago

Major Versions

0.2.0 → 1.392013-12-27

1.43.2 → 2.182018-06-10

### Community

Maintainers

![](https://www.gravatar.com/avatar/f84fb7d4b23ff09ef13958f4f84cc14e773b6b72f34f413ebdb0a6880bda0ef2?d=identicon)[rowanhill](/maintainers/rowanhill)

---

Top Contributors

[![rowanhill](https://avatars.githubusercontent.com/u/2607287?v=4)](https://github.com/rowanhill "rowanhill (265 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)")[![jworreth](https://avatars.githubusercontent.com/u/11389004?v=4)](https://github.com/jworreth "jworreth (3 commits)")[![codovo](https://avatars.githubusercontent.com/u/50177024?v=4)](https://github.com/codovo "codovo (1 commits)")

###  Code Quality

TestsPHPUnit

### Embed Badge

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

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

###  Alternatives

[stripe/stripe-php

Stripe PHP Library

4.0k143.3M480](/packages/stripe-stripe-php)[twilio/sdk

A PHP wrapper for Twilio's API

1.6k92.9M272](/packages/twilio-sdk)[facebook/php-business-sdk

PHP SDK for Facebook Business

90821.9M34](/packages/facebook-php-business-sdk)[meilisearch/meilisearch-php

PHP wrapper for the Meilisearch API

74513.7M114](/packages/meilisearch-meilisearch-php)[google/gax

Google API Core for PHP

265103.1M454](/packages/google-gax)[google/common-protos

Google API Common Protos for PHP

173103.7M50](/packages/google-common-protos)

PHPackages © 2026

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