ubirak / rest-api-behat-extension

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

Cannot check for empty array #101

Closed johnrhunt closed 5 years ago

johnrhunt commented 6 years ago

When I use:

  And the JSON node "data" should be equal to "[]"

I get the following:

 And the JSON node "data" should be equal to "[]"            # Ubirak\RestApiBehatExtension\Json\JsonContext::theJsonNodeShouldBeEqualTo()
      array(0) is not equal to string(2) '[]'
      -Expected
      +Actual
      @@ -2 +2,2 @@
      -string(2) "[]"
      +array(0) {
      +} (Ubirak\RestApiBehatExtension\Json\WrongJsonExpectation)

I've tried, but I can't figure out why this is happening. Can anyone shed some light on this? It looks to me like an empty array needs to get translated into the string [] by Ubirak

johnrhunt commented 6 years ago

The JSON I was running this against was:

{
  "data": []
}
bystro commented 6 years ago

You are right @johnrhunt :)

The code should be changed in the following https://github.com/ubirak/rest-api-behat-extension/blob/master/src/Json/JsonContext.php#L42 https://github.com/ubirak/rest-api-behat-extension/blob/master/src/Json/JsonContext.php#L179

However I think it should go more abstractly like And the JSON node "data" should be empty And the JSON should be empty

tyx commented 6 years ago

Hello !

You can use the JSON array node "data" should have 0 element

Hope it fits your need

tyx commented 6 years ago

But yes we could create a proxy around the empty use case ! Looks fine for me

johnrhunt commented 6 years ago

I followed @tyx 's recommendation - it worked lovely thank you.

shouze commented 5 years ago

@johnrhunt so, closing it