Let me try helping.
I assume that your postman request has a header Accept: application/json
, and that makes the $this->expectsJson()
to true
.
To make this work in your phpunit, you have to set the request header with the following:
public function test_categories_cannot_create_without_payload_should_receive_422()
{
$response = $this->withHeader([
'accept' => 'application/json'
])->post(route('categories.store'), []);
$response->assertStatus(Response::HTTP_UNPROCESSABLE_ENTITY);
$response->assertJson([
'message',
'errors',
]);
}
This should pass the assert status with 422 instead of 302.
Hope you find this helpful.
Regards,