I am running some HTTP tests in Laravel 5.4, mainly using the assertJson helper method with phpunit. When I run other tests on my models using assertEquals I usually get very good feedback about specifically which properties, fields, etc. are different than expected. However, the assertJson
method only tells me that there are differences, but not what those differences are. For instance, let's say I have a route my/route
that returns this JSON:
{
"name": "test",
"foo": "bar"
}
I might run this Laravel test:
$response = $this->get("my/route");
$response->assertJson([
'name' => 'test',
'foo' => 'baz',
]);
My test fails as expected. However, the resulting message is pretty unhelpful:
Failed asserting that an array has the subset Array &0 (
'name' => 'test'
'foo' => 'baz'
).
For a non-trivial example with larger response, it can get pretty annoying to try to figure out what is different between the JSON responses. Is there any way to view the specific differences between the expected and actual outputs, instead of just knowing that something is different between the two?