Skip to content

Assertions for verifying the data types of arrays #19

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

Merged
merged 2 commits into from
Apr 23, 2020

Conversation

jasonmccreary
Copy link
Owner

This PR is inspired by #16067. It provides this functionality by adding an assertJsonTypedStructure method on the TestResponse class.

For example, the following JSON response:

{
   "name": "Jason McCreary",
   "age": 38,
   "height": 6.1,
   "male": true,
   "attributes": {
      "hair":"brown",
      "eyes":"brown"
   },
   "hobbies": ["programming", "woodworking", "cooking"],
   "languages": [
      {"name":"PHP"},
      {"name":"JavaScript"}
   ]
}

Could be verified with:

$response->assertJsonTypedStructure([
    'name' => 'string',
    'age' => 'integer',
    'height' => 'number',
    'male' => 'boolean',
    'attributes' => [
        'hair' => 'string',
        'eyes' => 'string',
    ],
    'hobbies' => 'array'
    'languages' => [
        '*' => [
            'name' => 'string',
        ]
    ],
]);

The underlying verification of the array structure was also broken out to a generic assertArrayStructure method on the AdditionalAssertions trait.

@jasonmccreary jasonmccreary merged commit 728fcf4 into master Apr 23, 2020
@jasonmccreary jasonmccreary deleted the assert-json-type-structure branch April 23, 2020 15:33
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.

1 participant