Download the PHP package shiishiji/wiremock-php without Composer
On this page you can find all versions of the php package shiishiji/wiremock-php. It is possible to download/install these versions without Composer. Possible dependencies are resolved automatically.
Download shiishiji/wiremock-php
More information about shiishiji/wiremock-php
Files in shiishiji/wiremock-php
Package wiremock-php
Short Description PHP API for WireMock JSON interface
License MIT
Homepage http://github.com/rowanhill/wiremock-php
Informations about the package wiremock-php
wiremock-php 
Stub and mock web services with the power of 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
Like the idea of stubbing & verifying HTTP requests, but don't like this library (maybe you don't want to install Java)? You might want to investigate the following:
Installation
It's easiest to install wiremock-php via Composer:
Usage
API
The API is based directly on WireMock's Java API, so see the WireMock documentation for general help with interacting with WireMock.
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.
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
A typical usage looks something like the following:
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
.
All versions of wiremock-php with dependencies
ext-curl Version *
php Version >=8.0
symfony/serializer Version ^5.4
symfony/property-access Version ^5.4
symfony/property-info Version ^5.4