Skip to content

Commit

Permalink
Merge pull request #102 from richardgaunt/master
Browse files Browse the repository at this point in the history
Json path expression should have a result does not check for empty result list
  • Loading branch information
stephpy authored Jan 14, 2021
2 parents 5421575 + e63f5b7 commit 1c0b3ce
Show file tree
Hide file tree
Showing 3 changed files with 8 additions and 2 deletions.
1 change: 0 additions & 1 deletion .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,6 @@ before_script:
if [ ! $(php -m | grep -ci xdebug) -eq 0 ] ; then
phpenv config-rm xdebug.ini
fi
- composer global require hirak/prestissimo
- composer update $COMPOSER_PREFER
- |
# We force latest atoum on php >=7
Expand Down
2 changes: 2 additions & 0 deletions features/json_inspection.feature
Original file line number Diff line number Diff line change
Expand Up @@ -143,6 +143,7 @@ Feature: Test json inspection payload

Scenario: JSON path expression equal to inline json
Then the JSON path expression "foos[?foo == 'bar'].bar" should be equal to json '["bar"]'
Then the JSON path expression "foos[?foo == 'nobar'].bar" should be equal to json '[]'

Scenario: JSON path expression equal to given json
Then the JSON path expression "foos[?foo == 'bar'].bar" should be equal to:
Expand All @@ -155,3 +156,4 @@ Feature: Test json inspection payload

Scenario: JSON path expression have result
Then the JSON path expression "fooo.bar" should not have result
Then the JSON path expression "foos[?foo == 'nobar'].bar" should not have result
7 changes: 6 additions & 1 deletion src/Json/JsonContext.php
Original file line number Diff line number Diff line change
Expand Up @@ -219,6 +219,7 @@ public function theJsonPathExpressionShouldHaveResult($pathExpression)
{
$json = $this->jsonInspector->searchJsonPath($pathExpression);
$this->asserter->variable($json)->isNotNull();
$this->asserter->variable($json)->isNotEqualTo([]);
}

/**
Expand All @@ -227,7 +228,11 @@ public function theJsonPathExpressionShouldHaveResult($pathExpression)
public function theJsonPathExpressionShouldNotHaveResult($pathExpression)
{
$json = $this->jsonInspector->searchJsonPath($pathExpression);
$this->asserter->variable($json)->isNull();
if (is_array($json) && empty($json)) {
$this->asserter->variable($json)->isEqualTo([]);
} else {
$this->asserter->variable($json)->isNull();
}
}

private function evaluateJsonNodeValue($jsonNode)
Expand Down

0 comments on commit 1c0b3ce

Please sign in to comment.