Skip to content

Commit

Permalink
Merge pull request #19 from MacPaw/develop
Browse files Browse the repository at this point in the history
Release
  • Loading branch information
serhiidonii authored Feb 16, 2024
2 parents 62e4f77 + 99ab98c commit 389a36f
Showing 1 changed file with 52 additions and 0 deletions.
52 changes: 52 additions & 0 deletions src/Context/ApiContext.php
Original file line number Diff line number Diff line change
Expand Up @@ -301,6 +301,58 @@ protected function compareStructureResponse(string $variableFields, PyStringNode
}
}

/**
* @Then the :headerName response headers contains :headerValue
*/
public function theResponseHeadersContains(string $headerName, string $headerValue): void
{
$this->checkResponseHeader($headerName, $headerValue);
}

/**
* @And the :headerName response headers contains :headerValue
*/
public function theAndResponseHeadersContains(string $headerName, string $headerValue): void
{
$this->checkResponseHeader($headerName, $headerValue);
}

protected function checkResponseHeader(string $headerName, string $headerValue): void
{
$givenHeaderName = $this->stringManager->substituteValues(
$this->savedValues,
trim($headerName),
);
$givenHeaderValue = $this->stringManager->substituteValues(
$this->savedValues,
trim($headerValue),
);

$response = $this->getResponse();

if (!$response->headers->has($givenHeaderName)) {
$message = sprintf(
'Response header %s does not exists',
$givenHeaderName,
);

throw new RuntimeException($message);
}

$responseHeaderValue = $response->headers->get($givenHeaderName);

if (null === $responseHeaderValue || !substr_count($responseHeaderValue, $givenHeaderValue) > 0) {
$message = sprintf(
'Response header %s does not match. Expected: %s, given value: %s',
$givenHeaderName,
$givenHeaderValue,
$responseHeaderValue,
);

throw new RuntimeException($message);
}
}

protected function convertRunnableCodeParams(array $requestParams): array
{
foreach ($requestParams as $key => $value) {
Expand Down

0 comments on commit 389a36f

Please sign in to comment.