-
Notifications
You must be signed in to change notification settings - Fork 11.1k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
assertJsonStructure breaks comparing structure with itself #28591
Comments
Why would you want to do this? Can you provide a full test for this? |
Well, this is just a test case to demonstrate the problem.
|
I would expect the assert to pass if the structure matches, even if the id and role values are not the same. |
Hmm, I think you're maybe right. It seems to me that the
But this has been around for two years already and no-one ever reported problems with this so I'm not really sure if it's broken or not: #17700 Maybe if I can ping the original author (@cretueusebiu) he can explain why this is implemented as |
There are also no tests for the second |
At that time I just ported the method from the browser-kit-testing repo. |
I finally get what's happening. The thing is that the @DerManoMann what you need to do is this: $response->assertJsonStructure(['data' => ['user_id', 'role']]); The docs could use an example. I'll try to send in a PR for this but feel free to beat me to it. |
I thought it might be something like that, although I am not convinced this is a good solution. At the minimum it is not intuitive at all. The thing is, the method makes me compare an array (or object) with string keys (properties) with an array that has those as values with numeric keys. Personally, I'd be much happier wtith something that really compares two structures while ignoring all values except for array/object. Anyway, thanks for looking into this, I do appreciate your time. |
Description:
Comparing a data structure with itself beaks with message
Failed asserting that an array has the key 1.
Using
assertExactJson
does work, though.Steps To Reproduce:
The text was updated successfully, but these errors were encountered: