summaryrefslogtreecommitdiffstats
path: root/tests/RecordingTransport.php
diff options
context:
space:
mode:
authorMurilo Ijanc <[email protected]>2026-07-26 14:58:55 -0300
committerMurilo Ijanc <[email protected]>2026-07-26 14:58:55 -0300
commit64764fb9fac0227f8e0443e7c7519d73aec275b9 (patch)
treecb4fc56eeb6ecce53854f9c530609cf01ab3349f /tests/RecordingTransport.php
downloadphp-1fd1470890518a68130b3b9058fe1bebddca9f07.tar.gz
Initial importv0.1.0
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;
+ }
+}