pock

Client integrations

PSR-18 and HTTPlug

getClient() returns Pock\Client , which implements PSR-18, HTTPlug's synchronous client, and HTTPlug's asynchronous client:

$client = $pock->getClient();
$response = $client->sendRequest($request);
$promise = $client->sendAsyncRequest($request);

The asynchronous promise is already fulfilled for static and successful dynamic responses. Exceptions produce a rejected promise and are rethrown by wait() .

Symfony HTTP Client

Install Symfony HTTP Client in the consuming application:

composer require --dev symfony/http-client
$pock->matchMethod(RequestMethod::POST)
    ->matchUri('https://api.example.com/users?page=2')
    ->matchHeader('X-Token', 'secret')
    ->matchJsonBody(['name' => 'Jane'])
    ->reply(201)
    ->withHeader('Content-Type', 'application/json')
    ->withJson(['id' => 42]);

$client = $pock->getSymfonyClient();
$response = $client->request('POST', 'https://api.example.com/users', [
    'query' => ['page' => 2],
    'headers' => ['X-Token' => 'secret'],
    'json' => ['name' => 'Jane'],
]);

assert(['id' => 42] === $response->toArray());

The adapter supports headers , query , json , body , auth_basic , auth_bearer , and base_uri . withOptions() is available on Symfony versions whose contract defines it. Resource and callback request bodies are normalized before matching.

Symfony response semantics remain intact: getContent() and toArray() throw for error statuses unless their $throw argument is false. Pock transport failures are exposed as Symfony transport exceptions with the original exception as their previous exception. Responses can also be consumed through HttpClientInterface::stream() .

Search results