Skip to content
This repository has been archived by the owner on Apr 20, 2021. It is now read-only.

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

Open
alexislefebvre opened this issue Sep 25, 2018 · 0 comments
Open

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

alexislefebvre opened this issue Sep 25, 2018 · 0 comments

Comments

@alexislefebvre
Copy link

alexislefebvre commented Sep 25, 2018

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?

alexislefebvre added a commit to alexislefebvre/contexts that referenced this issue Oct 16, 2018
alexislefebvre added a commit to alexislefebvre/contexts that referenced this issue Oct 16, 2018
alexislefebvre added a commit to alexislefebvre/contexts that referenced this issue Oct 17, 2018
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant