The last document has all users with an empty roles array and the assertion fails when it should pass:
{
"users": [
{
"id": 1,
"roles": []
}
]
}
The second example is supplied to justify the fact the last assertion must pass. It shows that the assertion passes for empty arrays.
This issue arose in a real project of mine where I had a paginated resource. On some pages I had some users with roles and the assertion passed. On the other pages, all the users had empty roles array and the assertion unexpectedly failed. The problem here is that I can not see any elegant ways to work around the issue.
Thanks! Currently we don't have an opportunity to dive into context to figure out the issue.
Maybe you could help us?
Seems like the problem somewhere in Util/JsonType file? Probably you could figure it out?
I believe the
seeResponseMatchesJsonType()
assert is broken and I've added a failing test to illustrate this.We are going to test different JSON documents against the same assertion. The assertion is:
It means: "Each of the users (if any) and each of his roles(is any) must have a string property
name
. The if any part is crucial here.The first document has non-empty
roles
for all users and the assertion passes:The second document has non-empty
roles
for some of the users and the assertion passes:The last document has all users with an empty
roles
array and the assertion fails when it should pass:The second example is supplied to justify the fact the last assertion must pass. It shows that the assertion passes for empty arrays.
This issue arose in a real project of mine where I had a paginated resource. On some pages I had some users with roles and the assertion passed. On the other pages, all the users had empty roles array and the assertion unexpectedly failed. The problem here is that I can not see any elegant ways to work around the issue.