diff options
| author | Murilo Ijanc <[email protected]> | 2026-07-26 14:58:55 -0300 |
|---|---|---|
| committer | Murilo Ijanc <[email protected]> | 2026-07-26 14:58:55 -0300 |
| commit | 64764fb9fac0227f8e0443e7c7519d73aec275b9 (patch) | |
| tree | cb4fc56eeb6ecce53854f9c530609cf01ab3349f /tests/RecordingTransport.php | |
| download | php-1fd1470890518a68130b3b9058fe1bebddca9f07.tar.gz | |
Initial importv0.1.0
Diffstat (limited to 'tests/RecordingTransport.php')
| -rw-r--r-- | tests/RecordingTransport.php | 39 |
1 files changed, 39 insertions, 0 deletions
diff --git a/tests/RecordingTransport.php b/tests/RecordingTransport.php new file mode 100644 index 0000000..da93fb3 --- /dev/null +++ b/tests/RecordingTransport.php @@ -0,0 +1,39 @@ +<?php + +declare(strict_types=1); + +namespace Cepis\Tests; + +use Cepis\NetworkException; +use Cepis\Response; +use Cepis\Transport; + +/** + * Records what the client asked for and replays a canned list of responses. + * + * Used only to test the seam itself — what the client passes an implementer, + * and how it reacts to what one returns. Every test of the client's own + * behaviour goes over a real socket to {@see TestServer}. + */ +final class RecordingTransport implements Transport +{ + /** @var list<array{url: string, headers: array<string, string>, timeout: float}> */ + public array $calls = []; + + /** @param list<Response> $responses */ + public function __construct(private array $responses = []) + { + } + + public function get(string $url, array $headers, float $timeout): Response + { + $this->calls[] = ['url' => $url, 'headers' => $headers, 'timeout' => $timeout]; + + $response = array_shift($this->responses); + if ($response === null) { + throw new NetworkException('no response left for ' . $url); + } + + return $response; + } +} |