Add a failing test for JsonType assert #61
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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.