-
Notifications
You must be signed in to change notification settings - Fork 34
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Implemented step theResponseShouldContainPartialJson #49
base: master
Are you sure you want to change the base?
Changes from 1 commit
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -202,6 +202,31 @@ public function theResponseShouldContainJson(PyStringNode $jsonString) | |
} | ||
} | ||
|
||
/** | ||
* @Given /^the response should contain partial json:$/ | ||
*/ | ||
public function theResponseShouldContainPartialJson(PyStringNode $jsonString) | ||
{ | ||
|
||
$etalon = json_decode($this->replacePlaceHolder($jsonString->getRaw()), true); | ||
$actual = json_decode($this->browser->getLastResponse()->getContent(), true); | ||
|
||
if (null === $etalon) { | ||
throw new \RuntimeException( | ||
"Can not convert etalon to json:\n".$this->replacePlaceHolder($jsonString->getRaw()) | ||
); | ||
} | ||
|
||
$etalonKeys = array_keys($etalon); | ||
$actualKeys = array_keys($actual); | ||
$keys = array_intersect($etalonKeys, $actualKeys); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. ths looks wrong to me. All keys of the etalon should be checked. Your current implementation will not fail if the returned response is missing an expected key There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. But this is the goal: I don't want to check all the keys of the returned response, only the ones of the etalon. But OK the implementation is over complicated. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. the issue is that you were not checking all keys of the etalon either. Because of this line, you were checking that keys being in both are the same, not that keys being in the etalon are present in the output with the right value. The following case would have passed: Then the response should contain partial json:
"""
{ "foo": "bar" }
""" when the response contains { "invalid": "response" } |
||
|
||
foreach ($keys as $key) { | ||
assertArrayHasKey($key, $etalon); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. this does not make sense. you should assert what the response contain, not what the etalon contains There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. You are right. |
||
assertEquals($etalon[$key], $actual[$key]); | ||
} | ||
} | ||
|
||
/** | ||
* Prints last response body. | ||
* | ||
|
@@ -279,7 +304,7 @@ protected function addHeader($header) | |
{ | ||
$this->headers[] = $header; | ||
} | ||
|
||
/** | ||
* Removes a header identified by $headerName | ||
* | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
you also need to check `è$actual`` to avoid a fatal error on the typehint