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

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

@alexislefebvre

Description

@alexislefebvre

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?

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions