Uh oh!
There was an error while loading. Please reload this page.
- Notifications
You must be signed in to change notification settings - Fork 29
compare result of evaluated xpath expression to value#85
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
Merged
+99
−0
Merged
Changes from all commits
Commits
Show all changes
11 commits
Select commit
Hold shift + click to select a range
82a1c54
compare result of evaluated xpath expression to value
pamoller 05ab6a5
replace same instead equal
pamoller 79414f7
bug fix tests
pamoller 7c8556c
bug fix docu
pamoller b5cf63c
Change assertions to stricter
Naktibalda ef2af22
Revert test change, because evalueXpath returns float
Naktibalda d73d809
expect float
pamoller 8bf149a
bug fix float bug
pamoller 23316ed
revert to assertEquals
pamoller d7ea612
Use assertEquals in new methods
Naktibalda cbd3b88
Remoce unnecessary space
Naktibalda File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Uh oh!
There was an error while loading. Please reload this page.
Jump to
Jump to file
Failed to load files.
Loading
Uh oh!
There was an error while loading. Please reload this page.
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1100,6 +1100,67 @@ public function seeResponseJsonMatchesXpath(string $xPath): void | ||
| ); | ||
| } | ||
| /** | ||
| * Checks if applying xpath to json structure in response matches the expected result. | ||
| * JSON is not supposed to be checked against XPath, yet it can be converted to xml and used with XPath. | ||
| * This assertion allows you to check the structure of response json. | ||
| * * | ||
| * ```json | ||
| * { "store": { | ||
| * "book": [ | ||
| * { "category": "reference", | ||
| * "author": "Nigel Rees", | ||
| * "title": "Sayings of the Century", | ||
| * "price": 8.95 | ||
| * }, | ||
| * { "category": "fiction", | ||
| * "author": "Evelyn Waugh", | ||
| * "title": "Sword of Honour", | ||
| * "price": 12.99 | ||
| * } | ||
| * ], | ||
| * "bicycle": { | ||
| * "color": "red", | ||
| * "price": 19.95 | ||
| * } | ||
| * } | ||
| * } | ||
| * ``` | ||
| * | ||
| * ```php | ||
| * <?php | ||
| * // at least one book in store has author | ||
| * $I->seeResponseJsonXpathEvaluatesTo('count(//store/book/author) > 0', true); | ||
| * // count the number of books written by given author is 5 | ||
| * $I->seeResponseJsonMatchesXpath("//author[text() = 'Nigel Rees']", 1.0); | ||
| * ``` | ||
| * @part json | ||
| */ | ||
| public function seeResponseJsonXpathEvaluatesTo(string $xPath, $expected): void | ||
| { | ||
| $response = $this->connectionModule->_getResponseContent(); | ||
| $this->assertEquals( | ||
| $expected, | ||
| (new JsonArray($response))->evaluateXPath($xPath), | ||
| "Received JSON did not evualated XPath `{$xPath}` as expected.\nJson Response: \n" . $response | ||
| ); | ||
| } | ||
| /** | ||
| * Opposite to seeResponseJsonXpathEvaluatesTo | ||
| * | ||
| * @part json | ||
| */ | ||
| public function dontSeeResponseJsonXpathEvaluatesTo(string $xPath, $expected): void | ||
| { | ||
| $response = $this->connectionModule->_getResponseContent(); | ||
| $this->assertNotEquals( | ||
Naktibalda marked this conversation as resolved.
Uh oh!There was an error while loading. Please reload this page. | ||
| $expected, | ||
| (new JsonArray($response))->evaluateXPath($xPath), | ||
| "Received JSON did not evualated XPath `{$xPath}` as expected.\nJson Response: \n" . $response | ||
| ); | ||
| } | ||
| /** | ||
| * Opposite to seeResponseJsonMatchesXpath | ||
| * | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.