Easy-to-use HTTP mocking for tests, compatible with PSR-18, HTTPlug, and Symfony HTTP Client.
The project is still in its early development stage. Its API can change over time, although breaking changes are avoided where possible.
composer require --dev neur0toxine/pockuse Nyholm\Psr7\Factory\Psr17Factory;
use Pock\Enum\RequestMethod;
use Pock\PockBuilder;
$pock = new PockBuilder();
$pock->matchMethod(RequestMethod::GET)
->matchUri('https://api.example.com/users/42')
->reply(200)
->withHeader('Content-Type', 'application/json')
->withJson(['id' => 42, 'name' => 'Jane']);
$factory = new Psr17Factory();
$request = $factory->createRequest('GET', 'https://api.example.com/users/42');
$response = $pock->getClient()->sendRequest($request);
assert(200 === $response->getStatusCode());
assert(['id' => 42, 'name' => 'Jane'] === json_decode((string) $response->getBody(), true));Pass $pock->getClient() to code that expects a PSR-18 or HTTPlug client. Use $pock->getSymfonyClient() for code built on Symfony HTTP Client.
Read the usage guides for installation, compatibility, request matching, JSON, XML, response behavior, mock lifecycle, client integrations, and extension points.
The generated API reference documents every public class and method. The main entry points are PockBuilder and PockResponseBuilder.