Skip to content

Confusing assertJsonMatches exception message when arrays are equal but not same #127

@flohw

Description

@flohw

Hello,

I just faced an issue with assertJsonMatches method (note for search engine: which calls json()->assertMatches) can throw a weird exception message : (array:assoc)" to be the same as "(array:assoc)".

It turns out that's because I didn't ordered my array the same way the api endpoint tested returns its.

Value returned by the API:

{
    "errors": {
       "last_name": ["Invalid value"],
       "first_name": ["Invalid value"],
    }
}

Test:

assertJsonMatches('errors', [
    'first_name' => ['Invalid value'],
    'last_name' => ['Invalid value'],
]); // This will throw the exception message above

The same issue applies for multidimensional arrays.

I hope this can be easily fixed. I have no idea how for now. 🤯

Thank you!

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