*/ public array $requests = []; /** * @param array $queue */ public function __construct(private array $queue = []) {} public function request(string $method, $uri, array $options = []): ResponseInterface { $this->requests[] = [ 'method' => strtoupper($method), 'uri' => (string) $uri, 'options' => $options, ]; if ($this->queue !== []) { $next = array_shift($this->queue); if ($next instanceof Throwable) { throw $next; } if (is_callable($next)) { $result = $next($this, $method, $uri, $options); if ($result instanceof ResponseInterface) { return $result; } } if ($next instanceof ResponseInterface) { return $next; } } return new Response(200); } public function requestAsync($method, $uri, array $options = []): PromiseInterface { return new FulfilledPromise($this->request($method, $uri, $options)); } public function send(RequestInterface $request, array $options = []): ResponseInterface { return $this->request($request->getMethod(), $request->getUri(), $options + ['request' => $request]); } public function sendAsync(RequestInterface $request, array $options = []): PromiseInterface { return $this->requestAsync($request->getMethod(), $request->getUri(), $options + ['request' => $request]); } public function getConfig(?string $option = null): mixed { if ($option !== null) { throw new BadMethodCallException('Fake client does not expose configurable options.'); } return []; } public function append(ResponseInterface|Throwable|callable $next): void { $this->queue[] = $next; } }