Skip to content

Commit 5ca62bf

Browse files
authored
Merge pull request #64 from tyx/feature/search-json-expression
🆕 Add steps to ensure JSON path expression have result or not
2 parents a7ed36e + c9aa72a commit 5ca62bf

File tree

2 files changed

+26
-2
lines changed

2 files changed

+26
-2
lines changed

features/json_inspection.feature

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -124,11 +124,17 @@ Feature: Test json inspection payload
124124
}
125125
"""
126126

127-
Scenario: JSON path expression inline
127+
Scenario: JSON path expression equal to inline json
128128
Then the JSON path expression "foos[?foo == 'bar'].bar" should be equal to json '["bar"]'
129129

130-
Scenario: JSON path expression
130+
Scenario: JSON path expression equal to given json
131131
Then the JSON path expression "foos[?foo == 'bar'].bar" should be equal to:
132132
"""
133133
["bar"]
134134
"""
135+
136+
Scenario: JSON path expression have result
137+
Then the JSON path expression "fooo.foo" should have result
138+
139+
Scenario: JSON path expression have result
140+
Then the JSON path expression "fooo.bar" should not have result

src/Json/JsonContext.php

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -211,6 +211,24 @@ public function theJsonExpressionShouldBeEqualTo($pathExpression, PyStringNode $
211211
$this->theJsonPathExpressionShouldBeEqualToJson($pathExpression, (string) $expectedJson);
212212
}
213213

214+
/**
215+
* @Then the JSON path expression :pathExpression should have result
216+
*/
217+
public function theJsonPathExpressionShouldHaveResult($pathExpression)
218+
{
219+
$json = $this->jsonInspector->searchJsonPath($pathExpression);
220+
$this->asserter->variable($json)->isNotNull();
221+
}
222+
223+
/**
224+
* @Then the JSON path expression :pathExpression should not have result
225+
*/
226+
public function theJsonPathExpressionShouldNotHaveResult($pathExpression)
227+
{
228+
$json = $this->jsonInspector->searchJsonPath($pathExpression);
229+
$this->asserter->variable($json)->isNull();
230+
}
231+
214232
private function evaluateJsonNodeValue($jsonNode)
215233
{
216234
return $this->jsonInspector->readJsonNodeValue($jsonNode);

0 commit comments

Comments
 (0)