I'm trying to unit test and this is the output format of my api:
{
"data": {
"company": {
"idCompany": 1,
"name": "My Company",
"noUsers": 1,
"users": [
{
"idUser": 1,
"name": "John Doe"
}
]
}
}
}
My unit test is using:
$response
->assertStatus(200)
->assertJsonStructure($expected);
What is the format for the variable $expected
to match my json format?
You could also use the following
assertJsonStructure
to verify the structure of theJSON
return from your request.It will be enough that a key does not match for the test to fail.
Use seeJsonStructure() to check the structure of your json and pass it like this: