tests: Fix missing behat context methods

Signed-off-by: Julius Härtl <jus@bitgrid.net>
This commit is contained in:
Julius Härtl
2024-01-09 17:52:41 +01:00
parent 632871ad4d
commit dda1702afb
5 changed files with 25 additions and 30 deletions

View File

@@ -166,4 +166,29 @@ class RequestContext implements Context {
$this->getResponse()->getBody()->seek(0);
return json_decode((string)$this->getResponse()->getBody(), true);
}
/**
* @Given /^the response should be a list of objects$/
*/
public function theResponseShouldBeAListOfObjects() {
$jsonResponse = $this->getResponseBodyFromJson();
Assert::assertEquals(array_keys($jsonResponse), range(0, count($jsonResponse) - 1));
}
/**
* @When /^the response should contain an element with the properties$/
*/
public function responseContainsElement(TableNode $element) {
$json = $this->getResponseBodyFromJson();
$found = array_filter($json, function ($board) use ($element) {
foreach ($element as $row) {
if ($row['value'] !== $board[$row['property']]) {
return false;
}
}
return true;
});
Assert::assertEquals(1, count($found));
}
}