matcher = $matcher; $this->replyFactory = $replyFactory; $this->response = $response; $this->throwable = $throwable; $this->matchAt = $matchAt; $this->maxHits = $maxHits; $this->hits = 0; if ($this->maxHits < ($matchAt + 1) && -1 !== $this->maxHits) { $this->maxHits = $matchAt + 1; } } /** * @inheritDoc */ public function registerHit(): MockInterface { if (-1 !== $this->maxHits) { ++$this->hits; } return $this; } /** * @inheritDoc */ public function available(): bool { return -1 === $this->maxHits || $this->hits < $this->maxHits; } /** * @inheritDoc */ public function matches(RequestInterface $request): bool { if ($this->matcher->matches($request)) { if ($this->matchAt <= 0) { return true; } if ($this->matchAt === $this->hits) { return true; } $this->registerHit(); } return false; } /** * @inheritDoc */ public function getResponse(): ?ResponseInterface { if ( null !== $this->response && null !== $this->response->getBody() && $this->response->getBody()->isSeekable() ) { $this->response->getBody()->seek(0); } return $this->response; } /** * @inheritDoc */ public function getReplyFactory(): ?ReplyFactoryInterface { return $this->replyFactory; } /** * @inheritDoc */ public function getThrowable(RequestInterface $request): ?Throwable { if ($this->throwable instanceof PockRequestException || $this->throwable instanceof PockNetworkException) { return $this->throwable->setRequest($request); } return $this->throwable; } }