Creates an expectation with a response for a given request.

@param \Mcustiel\Phiremock\Domain\MockConfig $expectation
348422
public function createMockConfig(MockConfig $expectation)
    {
        $uri = $this->createBaseUri()->withPath(self::API_EXPECTATIONS_URL);
        // TODO: Add converter from expectation to array
        $body = @json_encode($expectation);
        if (false === $body) {
            throw new \RuntimeException('Error generating json body for request: ' . json_last_error_msg());
        }
        $request = (new PsrRequest())
            ->withUri($uri)
            ->withMethod('post')
            ->withHeader('Content-Type', 'application/json')
            ->withBody(new StringStream($body));
        $this->ensureIsNotErrorResponse($this->connection->send($request));
    }
239278
public static function typeMisMatch($expected, $actual)
    {
        return new static(
            sprintf(
                'Expected: "%s" Received: "%s"',
                $expected,
                is_object($actual) ? get_class($actual) : gettype($actual)
            )
        );
    }
365613
public static function assertEquals($actual, $expected, Throwable $exception)
    {
        static::makeAssertion($actual === $expected, $exception);
        return $actual;
    }
1152606
private function checkErrorResponse(ResponseInterface $response)
    {
        if ($response->getStatusCode() >= 500) {
            $errors = json_decode($response->getBody()->__toString(), true)['details'];

            throw new \RuntimeException(
                'An error occurred creating the expectation: '
                . ($errors ? var_export($errors, true) : '')
                . $response->getBody()->__toString());
        }

        if ($response->getStatusCode() >= 400) {
            throw new \RuntimeException('Request error while creating the expectation');
        }
    }
487937
public static function create(
        $expected,
        $actual,
        $paramNo = null,
        $code = null,
        $previous = null
    ) {
        $msgMsk = 'Expected %1$s. Got %2$s';

        if ($paramNo !== null) {
            $msgMsk = 'Param #%3$s '.lcfirst($msgMsk);
        }

        if ($code !== null) {
            $msgMsk = '[%4$s] '.$msgMsk;
        }

        $class = get_called_class();
        return new $class(
            sprintf(
                $msgMsk,
                $expected,
                Debug::summarise($actual),
                $paramNo,
                $code
            ),
            is_int($code) ? $code : null,
            $previous
        );
    }
986837
public void respond(final ExpectationResponseCallback expectationResponseCallback) {
        expectation.thenRespond(new HttpObjectCallback().withClientId(registerWebSocketClient(expectationResponseCallback)));
        mockServerClient.sendExpectation(expectation);
    }
960557
protected function createError(string $expectation, $value = null): Error
    {
        if ($value !== null) {
            $error = new Error('expected: %s found: %s', 1328557141, [$expectation, $this->renderValue($value)],
                'Validation Error');
        } else {
            $error = new Error($expectation, 1328557141, [], 'Validation Error');
        }
        return $error;
    }
7532
public function assertGreaterThanOrEqual($expected, $message = '')
    {
        Assert::assertGreaterThanOrEqual($expected, $this->getData(), $message);

        return $this;
    }
846328
private function constructResponse(array $listOfErrors, ResponseInterface $response)
    {
        $this->logger->debug('Adding Expectation->constructResponse');
        if (empty($listOfErrors)) {
            return $response->withStatus(201)->withBody(new StringStream('{"result" : "OK"}'));
        }

        return $this->constructErrorResponse($listOfErrors, $response);
    }
464908
public static function create($value, $expectedType, $message = null)
    {
        if ($message === null) {
            $errorMessage = sprintf('Expected %s, got %s', $expectedType, self::getStringRepresentation($value));
        } elseif ($message === '') {
            $errorMessage = sprintf('Expected %s', $expectedType);
        } else {
            $errorMessage = sprintf('Expected %s. %s', $expectedType, $message);
        }
        return $errorMessage;
    }
628866
public function setExpectedResult($expected = Table::RETURN_MODEL,
            $checkNotSet = false) {
        if (!$checkNotSet || ($checkNotSet && is_null($this->expected)))
                $this->expected = $expected;
        return $this;
    }
935751
protected function validateScenarioNameOrThrowException(
        MockConfig $expectation,
        LoggerInterface $logger
    ) {
        if (!$expectation->hasScenarioName()
            && ($expectation->getRequest()->hasScenarioState() || $expectation->getResponse()->hasNewScenarioState())
        ) {
            $logger->error('Scenario name related misconfiguration');
            throw new \RuntimeException(
                'Expecting or trying to set scenario state without specifying scenario name'
            );
        }
    }
1274427
public function getStrategyForExpectation(Expectation $expectation)
    {
        if (!empty($expectation->getProxyTo())) {
            return $this->diService->get(ProxyResponseStrategy::class);
        }
        if ($this->requestBodyOrUrlAreRegexp($expectation)) {
            return $this->diService->get(RegexResponseStrategy::class);
        }

        return $this->diService->get(HttpResponseStrategy::class);
    }
299006
public static function invalidEntityType($expected, $actual)
    {
        return new self(sprintf(
            'Entity must be an instance of "%s"; got "%s".',
            $expected,
            is_object($actual) ? get_class($actual) : gettype($actual)
        ));
    }
1236192
public function prefix($expected = null)
    {
        $current = null;

        if ($this->Controller->request->prefix !== null) {
            $current = $this->Controller->request->prefix;
        }

        if ($current == $expected) {
            return true;
        }

        return false;
    }
140023
protected function processResponse(Response $response, $expectedCode = 200)
	{
		if (202 == $response->code)
		{
			throw new \DomainException(
				'GitHub is building the statistics data. Please try again in a few moments.',
				$response->code
			);
		}

		return parent::processResponse($response, $expectedCode);
	}
739767
protected function assertNotSame($expected, $actual, $message = '')
    {
        \PHPUnit\Framework\Assert::assertNotSame($expected, $actual, $message);
    }