Skip to content

Commit

Permalink
ORC-400: Add headers checks to existing composer behat package
Browse files Browse the repository at this point in the history
Signed-off-by: Serhii Donii <serhii.donii@macpaw.com>
  • Loading branch information
serhiidonii committed Feb 15, 2024
1 parent b6fd441 commit 996c479
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

Check warning on line 307 in src/Context/ApiContext.php

View check run for this annotation

Codecov / codecov/patch

src/Context/ApiContext.php#L307

Added line #L307 was not covered by tests
{
$this->checkResponseHeader($headerName, $headerValue);

Check warning on line 309 in src/Context/ApiContext.php

View check run for this annotation

Codecov / codecov/patch

src/Context/ApiContext.php#L309

Added line #L309 was not covered by tests
}

/**
* @And the :headerName response headers contains :headerValue
*/
public function theAndResponseHeadersContains(string $headerName, string $headerValue): void

Check warning on line 315 in src/Context/ApiContext.php

View check run for this annotation

Codecov / codecov/patch

src/Context/ApiContext.php#L315

Added line #L315 was not covered by tests
{
$this->checkResponseHeader($headerName, $headerValue);

Check warning on line 317 in src/Context/ApiContext.php

View check run for this annotation

Codecov / codecov/patch

src/Context/ApiContext.php#L317

Added line #L317 was not covered by tests
}

protected function checkResponseHeader(string $headerName, string $headerValue): void

Check warning on line 320 in src/Context/ApiContext.php

View check run for this annotation

Codecov / codecov/patch

src/Context/ApiContext.php#L320

Added line #L320 was not covered by tests
{
$givenHeaderName = $this->stringManager->substituteValues(
$this->savedValues,
trim($headerName),

Check warning on line 324 in src/Context/ApiContext.php

View check run for this annotation

Codecov / codecov/patch

src/Context/ApiContext.php#L322-L324

Added lines #L322 - L324 were not covered by tests
);
$givenHeaderValue = $this->stringManager->substituteValues(
$this->savedValues,
trim($headerValue),

Check warning on line 328 in src/Context/ApiContext.php

View check run for this annotation

Codecov / codecov/patch

src/Context/ApiContext.php#L326-L328

Added lines #L326 - L328 were not covered by tests
);

$response = $this->getResponse();

Check warning on line 331 in src/Context/ApiContext.php

View check run for this annotation

Codecov / codecov/patch

src/Context/ApiContext.php#L331

Added line #L331 was not covered by tests

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

Check warning on line 336 in src/Context/ApiContext.php

View check run for this annotation

Codecov / codecov/patch

src/Context/ApiContext.php#L333-L336

Added lines #L333 - L336 were not covered by tests
);

throw new RuntimeException($message);

Check warning on line 339 in src/Context/ApiContext.php

View check run for this annotation

Codecov / codecov/patch

src/Context/ApiContext.php#L339

Added line #L339 was not covered by tests
}

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

Check warning on line 342 in src/Context/ApiContext.php

View check run for this annotation

Codecov / codecov/patch

src/Context/ApiContext.php#L342

Added line #L342 was not covered by tests

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

Check warning on line 349 in src/Context/ApiContext.php

View check run for this annotation

Codecov / codecov/patch

src/Context/ApiContext.php#L344-L349

Added lines #L344 - L349 were not covered by tests
);

throw new RuntimeException($message);

Check warning on line 352 in src/Context/ApiContext.php

View check run for this annotation

Codecov / codecov/patch

src/Context/ApiContext.php#L352

Added line #L352 was not covered by tests
}
}

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

0 comments on commit 996c479

Please sign in to comment.