Skip to content
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

Add a failing test for JsonType assert #61

Open
wants to merge 1 commit into
base: master
Choose a base branch
from

Conversation

Kolyunya
Copy link
Contributor

@Kolyunya Kolyunya commented Aug 1, 2021

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:

seeResponseMatchesJsonType(['name' => 'string'], '$.users.*.roles.*');

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:

{
  "users": [
    {
      "id": 1,
      "roles": [
        {
          "name": "admin"
        }
      ]
    }
  ]
}

The second document has non-empty roles for some of the users and the assertion passes:

{
  "users": [
    {
      "id": 1,
      "roles": [
        {
          "name": "admin"
        }
      ]
    },
    {
      "id": 2,
      "roles": []
    }
  ]
}

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.

@DavertMik
Copy link
Member

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?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants