The issue is that the assertJson method is not matching the expected JSON fragment with the actual JSON fragment. Instead, it is prepending the actual JSON fragment to the expected JSON fragment and then trying to match it. This is causing the test to fail.
To fix this issue, you can use the assertJsonFragment method instead of assertJson. The assertJsonFragment method will only check if the expected JSON fragment is present in the actual JSON response, without trying to match the entire JSON response.
Here's an example of how you can use assertJsonFragment in your test:
$this->postJson(
'api/products/dothing',
[
'id' => 'abc123',
'contents' => ['abc123'],
]
)
->assertJsonFragment(['type' => 'products']);
This should fix the issue and make your test pass.