Mock lifecycle and ordering
Each mock handles one matching request by default. The builder preserves definition order, and the first available matching mock wins.
$pock->matchUri('https://api.example.com/status')
->reply(503);
$pock->matchUri('https://api.example.com/status')
->reply(200);
The first request receives 503 and consumes the first mock; the second receives 200.
Repetition
repeat()
sets a finite number of responses. always()
prevents expiration:
$pock->matchPath('/retry')->repeat(3)->reply(503);
$pock->matchPath('/health')->always()->reply(200);
Non-positive values passed to repeat()
leave the current limit unchanged.
Matching a particular occurrence
at(N)
makes a mock available only at the specified zero-based prior-hit offset used by the builder; from a caller's perspective, at(2)
responds on the second matching occurrence:
$pock->matchPath('/event')->at(2)->reply(202);
$pock->always()->reply(404);
Be careful with several identical at()
definitions: an earlier matching mock can prevent later definitions from registering that occurrence. Prefer an explicit sequence of single-use mocks when exact response ordering is important.
Resetting
reset()
removes all accumulated mocks and restores the defaults. Create the client only after the complete sequence is defined:
$pock->reset();
$pock->matchUri('https://api.example.com/new-test')->reply(200);
$client = $pock->getClient();