neur0toxine / pock
PSR-18 compatible HTTP mock library
v0.13.0
2026-07-18 18:11 UTC
Requires
- php: >=7.2.0
- ext-json: *
- nyholm/psr7: ^1.4
- php-http/httplug: ^1.0 || ^2.0
- psr/http-client: ^1.0
- psr/http-message: ^1.0 || ^2.0
- riverline/multipart-parser: ^2.0.1
Requires (Dev)
- dealerdirect/phpcodesniffer-composer-installer: ^0.7.1 || ^1.0
- doctrine/annotations: ^1.13 || ^2.0
- jms/serializer: ^2.0 || ^3.17
- php-http/multipart-stream-builder: ^1.2
- phpcompatibility/php-compatibility: ^9.3
- phpmd/phpmd: ^2.12
- phpstan/phpstan: ^1.5
- phpunit/phpunit: ^8.5 || ^9.6
- squizlabs/php_codesniffer: ^3.6
- symfony/http-client: ^4.3 || ^5.0 || ^6.0 || ^7.0 || ^8.0
- symfony/property-access: ^5.2 || ^6.0 || ^7.0 || ^8.0
- symfony/serializer: ^5.2 || ^6.0 || ^7.0 || ^8.0
Suggests
- symfony/http-client: Required to use Pock as a Symfony HttpClientInterface mock.
Provides
README
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.