PSR-18 compatible HTTP mock library

Maintainers

Package info

github.com/Neur0toxine/pock

pkg:composer/neur0toxine/pock

Transparency log

Statistics

Installs: 46 543

Dependents: 7

Suggesters: 0

Stars: 4

Open Issues: 0

v0.13.0 2026-07-18 18:11 UTC

This package is auto-updated.

Last update: 2026-07-18 18:12:41 UTC


README

Build Status Coverage Latest stable PHP from Packagist License

pock

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.

Installation

composer require --dev neur0toxine/pock

Quick start

use 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.

Documentation

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.