PHPackages                             neur0toxine/pock - 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. [Testing &amp; Quality](/categories/testing)
4. /
5. neur0toxine/pock

ActiveLibrary[Testing &amp; Quality](/categories/testing)

neur0toxine/pock
================

PSR-18 compatible HTTP mock library

v0.12.2(2y ago)445.4k—0%2[1 issues](https://github.com/Neur0toxine/pock/issues)7MITPHPPHP &gt;=7.2.0

Since May 15Pushed 2y ago1 watchersCompare

[ Source](https://github.com/Neur0toxine/pock)[ Packagist](https://packagist.org/packages/neur0toxine/pock)[ Docs](https://github.com/Neur0toxine/pock)[ RSS](/packages/neur0toxine-pock/feed)WikiDiscussions master Synced 1mo ago

READMEChangelogDependencies (16)Versions (18)Used By (7)

[![Build Status](https://camo.githubusercontent.com/ddcf7c90df5c5ebc40462840aaf07d6f0f4733908eb57a2be25489f89601ca3c/68747470733a2f2f696d672e736869656c64732e696f2f6769746875622f616374696f6e732f776f726b666c6f772f7374617475732f4e65757230746f78696e652f706f636b2f74657374732e796d6c3f6272616e63683d6d6173746572267374796c653d666c61742d737175617265)](https://camo.githubusercontent.com/ddcf7c90df5c5ebc40462840aaf07d6f0f4733908eb57a2be25489f89601ca3c/68747470733a2f2f696d672e736869656c64732e696f2f6769746875622f616374696f6e732f776f726b666c6f772f7374617475732f4e65757230746f78696e652f706f636b2f74657374732e796d6c3f6272616e63683d6d6173746572267374796c653d666c61742d737175617265)[![Coverage](https://camo.githubusercontent.com/5449f4780241ded2b852ac1af0dcd26f4e447dc21e1fa40a2d30496cd62df620/68747470733a2f2f696d672e736869656c64732e696f2f636f6465636f762f632f67682f4e65757230746f78696e652f706f636b2f6d61737465722e7376673f6c6f676f3d636f6465636f76266c6f676f436f6c6f723d7768697465267374796c653d666c61742d737175617265)](https://codecov.io/gh/Neur0toxine/pock)[![Latest stable](https://camo.githubusercontent.com/64e51597120a4d8106e38f28dca5078e88e8df8faed3f537524fbe20ee551ef1/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f762f6e65757230746f78696e652f706f636b2e7376673f7374796c653d666c61742d737175617265)](https://packagist.org/packages/neur0toxine/pock)[![PHP from Packagist](https://camo.githubusercontent.com/e77365e2e2688f17abbdcacfcb737ac0cdc599ed4ec1d841e33550154f77905e/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f7068702d762f6e65757230746f78696e652f706f636b2e7376673f6c6f676f3d706870266c6f676f436f6c6f723d7768697465267374796c653d666c61742d737175617265)](https://packagist.org/packages/neur0toxine/pock)[![License](https://camo.githubusercontent.com/97da4f11df019933cee3f06b49bb9ca8a44278b61ea654da8b067a1e6c1959f2/68747470733a2f2f696d672e736869656c64732e696f2f6769746875622f6c6963656e73652f4e65757230746f78696e652f706f636b3f7374796c653d666c61742d737175617265)](https://camo.githubusercontent.com/97da4f11df019933cee3f06b49bb9ca8a44278b61ea654da8b067a1e6c1959f2/68747470733a2f2f696d672e736869656c64732e696f2f6769746875622f6c6963656e73652f4e65757230746f78696e652f706f636b3f7374796c653d666c61742d737175617265)

pock
====

[](#pock)

Easy to use HTTP mocking solution, compatible with PSR-18 and HTTPlug.

Project is still in its early development stage. API can change over time, but I'll try to not introduce breaking changes. You can find autogenerated documentation [here](https://neur0toxine.github.io/pock/) or look at the examples. API for the mock building can be found [here](https://neur0toxine.github.io/pock/classes/Pock-PockBuilder.html) and API for the response building (returned from `PockBuilder::reply` call) can be found [here](https://neur0toxine.github.io/pock/classes/Pock-PockResponseBuilder.html).

Examples
========

[](#examples)

Mock JSON API route with Basic authorization, reply with JSON.

```
use Pock\Enum\RequestMethod;
use Pock\Enum\RequestScheme;
use Pock\PockBuilder;

$builder = new PockBuilder();
$builder->matchMethod(RequestMethod::GET)
    ->matchScheme(RequestScheme::HTTPS)
    ->matchHost('example.com')
    ->matchPath('/api/v1/users')
    ->matchHeaders([
        'Content-Type' => 'application/json',
        'Authorization' => 'Basic YWxhZGRpbjpvcGVuc2VzYW1l'
    ])
    ->reply(200)
    ->withHeader('Content-Type', 'application/json')
    ->withJson([
        [
            'name' => 'John Doe',
            'username' => 'john',
            'email' => 'john@example.com'
        ],
        [
            'name' => 'Jane Doe',
            'username' => 'jane',
            'email' => 'jane@example.com'
        ],
    ]);

// Pass PSR-18 compatible client to the API client.
$client = new MysteriousApiClient($builder->getClient());
$client->setCredentials('username', 'password');

// Receive mock response.
$response = $client->getUsers();
```

Same mock, but with models! Also, the code itself is slightly shorter.

```
use Pock\Enum\RequestMethod;
use Pock\PockBuilder;

$builder = new PockBuilder();
$builder->matchMethod(RequestMethod::GET)
    ->matchUri('https://example.com/api/v1/users')
    ->matchHeaders([
        'Content-Type' => 'application/json',
        'Authorization' => 'Basic YWxhZGRpbjpvcGVuc2VzYW1l'
    ])
    ->reply(200)
    ->withHeader('Content-Type', 'application/json')
    ->withJson([
        // We're assuming here that MysteriousUser's constructor can receive an initial values.
        new MysteriousUser('John Doe', 'john', 'john@example.com'),
        new MysteriousUser('Jane Doe', 'jane', 'jane@example.com'),
    ]);

// Pass PSR-18 compatible client to the API client.
$client = new MysteriousApiClient($builder->getClient());
$client->setCredentials('username', 'password');

// Receive mock response.
$response = $client->getUsers();
```

It is possible to mock a response using DTO's because pock can use third-party serializers under the hood.

Serializer support
==================

[](#serializer-support)

pock supports JMS serializer and Symfony serializer out of the box. Available serializer will be instantiated automatically. It will be used to serialize requests and responses in mocks which means you actually can pass an entire DTO into the corresponding methods (for example, `matchJsonBody` as an assertion or `withJsonBody` to generate a response body).

By default, JMS serializer has more priority than the Symfony serializer. You can use methods below before running tests (`bootstrap.php`) if you want to override default behavior.

```
use Pock\Factory\JsonSerializerFactory;
use Pock\Factory\XmlSerializerFactory;
use Pock\Serializer\SymfonySerializerAdapter;
use Symfony\Component\Serializer\Encoder\JsonEncoder;
use Symfony\Component\Serializer\Encoder\XmlEncoder;
use Symfony\Component\Serializer\Normalizer\ObjectNormalizer;
use Symfony\Component\Serializer\Serializer;

$encoders = [new XmlEncoder(), new JsonEncoder()];
$normalizers = [new ObjectNormalizer()];
$serializer = new SymfonySerializerAdapter(new Serializer($normalizers, $encoders));

JsonSerializerFactory::setSerializer($serializer);
XmlSerializerFactory::setSerializer($serializer);
```

In order to use unsupported serializer you should create an adapter which implements `Pock\Serializer\SerializerInterface`.

Roadmap to stable
=================

[](#roadmap-to-stable)

- `at(N)` - execute mock only at Nth call.
- `always()` - always execute this mock (removes mock expiration).
- Separate `UniversalMockException` into several exceptions (`PockClientException`, `PockNetworkException`, etc).
- Add methods for easier throwing of exceptions listed in previous entry.
- `replyWithCallback` - reply using specified callback.
- `replyWithFactory` - reply using specified response factory (provide corresponding interface).
- Compare XML bodies using `DOMDocument`, fallback to text comparison in case of problems.
- Regexp matchers for body, query, URI and path.
- Form Data body matcher (partial &amp; exact)
- Multipart form body matcher (just like callback matcher but parses the body as a multipart form data)
- **BREAKING CHANGE:** Rename serializer decorators to serializer adapters.
- Real network response for mocked requests.
- `symfony/http-client` support.
- Document everything (with examples if it’s feasible).

###  Health Score

30

—

LowBetter than 64% of packages

Maintenance15

Infrequent updates — may be unmaintained

Popularity33

Limited adoption so far

Community16

Small or concentrated contributor base

Maturity45

Maturing project, gaining track record

 Bus Factor1

Top contributor holds 100% 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 ~58 days

Recently: every ~184 days

Total

16

Last Release

959d ago

### Community

Maintainers

![](https://www.gravatar.com/avatar/1e421901d9ce2555337064441185824281408c5cdcd1224ed74e824995c3afd0?d=identicon)[Neur0toxine](/maintainers/Neur0toxine)

---

Top Contributors

[![Neur0toxine](https://avatars.githubusercontent.com/u/24733820?v=4)](https://github.com/Neur0toxine "Neur0toxine (50 commits)")

---

Tags

apidtohttpjsonmocknetworkpockpsr-17psr-18psr-7serializerhttppsr-7symfonypsr-18mockphp-http

###  Code Quality

Static AnalysisPHPStan

Code StylePHP\_CodeSniffer

Type Coverage Yes

### Embed Badge

![Health badge](/badges/neur0toxine-pock/health.svg)

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

###  Alternatives

[php-http/mock-client

Mock HTTP client

719.7M781](/packages/php-http-mock-client)[elastic/transport

HTTP transport PHP library for Elastic products

2020.6M7](/packages/elastic-transport)[phpro/http-tools

HTTP tools for developing more consistent HTTP implementations.

28137.8k](/packages/phpro-http-tools)[osteel/openapi-httpfoundation-testing

Validate HttpFoundation requests and responses against OpenAPI (3+) definitions

1201.9M6](/packages/osteel-openapi-httpfoundation-testing)[art4/requests-psr18-adapter

Use WordPress/Requests as a PSR-18 HTTP client

153.3k](/packages/art4-requests-psr18-adapter)[amphp/http-client-psr7

PSR-7 adapter for Amp's HTTP client.

1454.7k4](/packages/amphp-http-client-psr7)

PHPackages © 2026

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