summaryrefslogtreecommitdiffstats
path: root/tests/RecordingTransport.php
diff options
context:
space:
mode:
Diffstat (limited to 'tests/RecordingTransport.php')
-rw-r--r--tests/RecordingTransport.php39
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;
+ }
+}