ubirak / rest-api-behat-extension

Stuff to easily test your rest api with Behat
MIT License
38 stars 24 forks source link

Json path expression should have a result does not check for empty result list #102

Closed richardgaunt closed 3 years ago

richardgaunt commented 4 years ago

When evaluating an expression like foos[?foo == 'nobar'].bar on the below example JSON, the returned value is [] rather than NULL. It returns an empty result list rather than a null value.

The library JsonContext::theJsonPathExpressionShouldHaveResult and JsonContext::theJsonPathExpressionShouldNotHaveResult() only check for NULL value when asserting whether there is a result passing the above expression.

This PR changes the evaluation to also check for an empty array and / or null value.

Example JSON: { "foo": "bar", "footrue": true, "foofalse": false, "foonull": null, "fooint": 1337, "foos": [ {"foo": "bar", "bar": "bar"}, {"foo2": "bar2"} ], "fooo": { "foo": "bar" }, "fooarray": [ "bar1", "bar2" ] }

stephpy commented 3 years ago

Sorry for delay, thank you for your job.