mocks = $mocks; $this->fallbackClient = $fallbackClient; } /** * @throws \Throwable */ public function doSendRequest(RequestInterface $request): ResponseInterface { return $this->sendAsyncRequest($request)->wait(); } /** * @inheritDoc * @throws \Throwable */ public function sendRequest(RequestInterface $request): ResponseInterface { return $this->doSendRequest($request); } /** * @inheritDoc * @throws \Throwable */ public function sendAsyncRequest(RequestInterface $request): Promise { foreach ($this->mocks as $mock) { if (!$mock->available()) { continue; } if ($mock->getMatcher()->matches($request)) { if (null !== $mock->getResponse()) { $mock->registerHit(); return new HttpFulfilledPromise($mock->getResponse()); } if (null !== $mock->getThrowable()) { $mock->registerHit(); return new HttpRejectedPromise($mock->getThrowable()); } throw new BrokenMockException($mock); } } if (null !== $this->fallbackClient) { try { return new HttpFulfilledPromise($this->fallbackClient->sendRequest($request)); } catch (Throwable $throwable) { return new HttpRejectedPromise($throwable); } } throw new UnsupportedRequestException(); } }