@param Expectation            $expectation
@param ServerRequestInterface $httpRequest
@param string                 $responseBody

@return string
186921
private function fillWithBodyMatches(Expectation $expectation, ServerRequestInterface $httpRequest, $responseBody)
    {
        if ($this->bodyConditionIsRegex($expectation)) {
            return $this->replaceMatches(
                'body',
                $expectation->getRequest()->getBody()->getValue(),
                $httpRequest->getBody()->__toString(),
                $responseBody
            );
        }

        return $responseBody;
    }
1095559
private function requestMethodMatchesExpectation(ServerRequestInterface $httpRequest, Request $expectedRequest)
    {
        $inputSource = $this->inputSourceFactory->createFromConfig([
            'method' => null,
        ]);
        $matcher = $this->matcherFactory->createFromConfig([
            Matchers::SAME_STRING => $expectedRequest->getMethod(),
        ]);

        return $this->evaluate($inputSource, $matcher, $httpRequest);
    }
229074
private function bodyConditionIsRegex(Expectation $expectation)
    {
        return $expectation->getRequest()->getBody()
            && Matchers::MATCHES === $expectation->getRequest()->getBody()->getMatcher();
    }
407275
private function searchForExecutionsCount(Expectation $expectation)
    {
        $count = 0;
        foreach ($this->requestsStorage->listRequests() as $request) {
            if ($this->comparator->equals($request, $expectation)) {
                ++$count;
            }
        }

        return $count;
    }
370471
public function thenRespond($statusCode, $body)
    {
        $response = ResponseBuilder::create($statusCode)->andBody($body)->build()[1];

        return $this->expectation->setResponse($response);
    }
419727
private function getResponseWithBody(HttpResponse $responseConfig, ResponseInterface $httpResponse)
    {
        if ($responseConfig->getBody()) {
            $httpResponse = $httpResponse->withBody(new StringStream($responseConfig->getBody()->asString()));
        }

        return $httpResponse;
    }
471785
private function checkStatus($expectedStatus)
    {
        $status = $this->response->getStatusCode();
        
        if ($status != $expectedStatus) {
            throw new EndpointException("Unexpected HTTP status {$status} " . $this->response->getReasonPhrase());
        }
    }
921377
private function compareRequestParts(ServerRequestInterface $httpRequest, RequestConditions $expectedRequest)
    {
        $atLeastOneExecution = false;
        $requestParts = ['Method', 'Url', 'Body'];

        foreach ($requestParts as $requestPart) {
            $getter = "get{$requestPart}";
            $matcher = "request{$requestPart}MatchesExpectation";
            if ($expectedRequest->{$getter}()) {
                $this->logger->debug("Checking {$requestPart} against expectation");
                if (!$this->{$matcher}($httpRequest, $expectedRequest)) {
                    return null;
                }
                $atLeastOneExecution = true;
            }
        }

        return $atLeastOneExecution;
    }
320451
private function requestBodyOrUrlAreRegexp(Expectation $expectation)
    {
        return $expectation->getRequest()->getBody()
            && Matchers::MATCHES === $expectation->getRequest()->getBody()->getMatcher()
            || $expectation->getRequest()->getUrl()
            && Matchers::MATCHES === $expectation->getRequest()->getUrl()->getMatcher();
    }
50726
private function getNextMatchingExpectation($lastFound, ServerRequestInterface $request, MockConfig $expectation)
    {
        if ($this->comparator->equals($request, $expectation)) {
            if (null === $lastFound || $expectation->getPriority() > $lastFound->getPriority()) {
                $lastFound = $expectation;
            }
        }

        return $lastFound;
    }
1115059
private function requestBodyMatchesExpectation(ServerRequestInterface $httpRequest, RequestConditions $expectedRequest)
    {
        $inputSource = $this->inputSourceLocator->locate('body');
        $matcher = $this->matcherLocator->locate(
            $expectedRequest->getBody()->getMatcher()->asString()
        );

        return $matcher->match(
            $inputSource->getValue($httpRequest),
            $expectedRequest->getBody()->getValue()->asString()
        );
    }
271029
private function validateJsonResponse($responseBody)
    {
        $data = json_decode($responseBody);

        if (json_last_error() !== JSON_ERROR_NONE) {
            throw new \Exception('Error decoding JSON.');
        }

        if (isset($data->error)) {
            throw new \Exception($data->error->error_message);
        }

        if (empty($data)) {
            throw new \Exception('No results found.');
        }

        return $responseBody;
    }
433445
private function requestUrlMatchesExpectation(ServerRequestInterface $httpRequest, RequestConditions $expectedRequest)
    {
        $inputSource = $this->inputSourceLocator->locate('url');
        $matcher = $this->matcherLocator->locate($expectedRequest->getUrl()->getMatcher()->asString());

        return $matcher->match(
            $inputSource->getValue($httpRequest),
            $expectedRequest->getUrl()->getValue()->asString()
        );
    }
1119038
protected function validateExpectationOrThrowException(Expectation $expectation, LoggerInterface $logger)
    {
        $this->validateRequestOrThrowException($expectation, $logger);
        $this->validateResponseOrThrowException($expectation, $logger);
        $this->validateScenarioConfigOrThrowException($expectation, $logger);
    }
146347
public function seeInEmailHtmlBody($expected)
    {
        $email = $this->fetchLastMessage();
        $this->assertContains($expected, $email->html_body, 'Email body contains HTML');
    }
408969
private function _processProcessorResponse($response, $expectedType)
    {
        $transactionId = (isset($response->Header->GatewayTxnId) ? $response->Header->GatewayTxnId : null);
        $item = $response->Transaction->$expectedType;

        if ($item != null) {
            $responseCode = (isset($item->RspCode) ? $item->RspCode : null);
            $responseMessage = (isset($item->RspMessage) ? $item->RspMessage : null);

            if ($responseCode == null && isset($item->TransactionStatus->RspCode)) {
                $responseCode = $item->TransactionStatus->RspCode;
            }
            if ($responseMessage == null && isset($item->TransactionStatus->RspText)) {
                $responseMessage = $item->TransactionStatus->RspText;
            }

            HpsProcessorResponseValidation::checkResponse($transactionId, $responseCode, $responseMessage, $item);
        }
    }
400765
protected function emitRestRequest(array $httpRequest)
    {
        $body = '';
        $headers = [
            'Content-type: application/json'
        ];

        if (array_key_exists('headers', $httpRequest['request'])) {
            foreach ($httpRequest['request']['headers'] as $header => $value) {
                $headers[] = ucfirst($header) . ': ' . $value;
            }
        }
        $headers[] = 'X-Kuzzle-Volatile: ' . json_encode(array_merge($this->getVolatile(), ['sdkVersion' => $this->getSdkVersion()]));

        if (array_key_exists('body', $httpRequest['request'])) {
            $body = json_encode($httpRequest['request']['body']);
            $headers[] = 'Content-length: ' . strlen($body);
        }

        $result = $this->requestHandler->execute([
            'url' => $this->url . $httpRequest['route'],
            'method' => $httpRequest['method'],
            'headers' => $headers,
            'body' => $body,
            'query_parameters' => $httpRequest['query_parameters']
        ]);

        if (!empty($result['error'])) {
            $this->emitEvent('queryError', $result['error'], $httpRequest);
            throw new ErrorException($result['error']);
        }

        $response = json_decode($result['response'], true);

        /**
         * @todo: manage custom exceptions
         */
        if (!empty($response['error'])) {
            $this->emitEvent('queryError', $response['error'], $httpRequest);
            throw new ErrorException($response['error']['message']);
        }

        return $response;
    }