Behatch / contexts

Behat extension with most custom helper steps
Other
394 stars 203 forks source link

[JsonContext] How to handle integers as strings? #263

Open alexislefebvre opened 5 years ago

alexislefebvre commented 5 years ago

I'm storing postal codes as string (because it's a recommended way), when I store a postal code like 44000 in my API, it's stored as a string and data is rendered as postalCode: "44000" in the JSON produced by the API.

I have the following Behat step:

And the JSON node "postalCode" should be equal to the string "44000"

This test fails because the expected value 44000 is casted to an integer by PHP in theJsonNodeShouldBeEqualToTheString. Calls to var_dump() show that the actual text is string(5) "44000" but the expected text is int(44000).. So the expression ($actual !== $text) fails and the test fail.

I can use the following step in order to remove variable type check:

And the JSON node "postalCode" should be equal to "44000"

But I'm still wondering how theJsonNodeShouldBeEqualToTheString should work when a string is seen by PHP as an integer. Should expected value be cast to strings?