Skip to content
This repository was archived by the owner on Sep 15, 2022. It is now read-only.
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
26 changes: 21 additions & 5 deletions src/Knp/FriendlyContexts/Context/ApiContext.php
Original file line number Diff line number Diff line change
Expand Up @@ -198,7 +198,7 @@ public function iShouldReceiveResponse($httpCode, $shortType = null)
));
}
}

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This space is a mistake, I think it's your IDE which added it 😉

/**
* @Then /^the response should contains the following headers:?$/
*/
Expand All @@ -209,10 +209,26 @@ public function theResponseShouldContainsHeaders(TableNode $headerTable)
}

$expectedHeaders = $headerTable->getRowsHash();
$this->getAsserter()->assertArrayContains(
$expectedHeaders,
$this->response->getHeaders()
);
$existingHeaders = $this->response->getHeaders()->toArray();

foreach ($expectedHeaders as $key => $value) {
if (false === array_key_exists($key, $existingHeaders)) {
throw new \Exception(sprintf(
'No header names "%s" found. "%s" available.',
$key,
implode('", "', array_keys($existingHeaders))
));
}
$real = $existingHeaders[$key];
array_map('trim', $real);
sort($real);

$expected = array($value);
array_map('trim', $expected);
sort($expected);

$this->getAsserter()->assertArrayEquals($expected, $real);
}
}

/**
Expand Down