79540696

Date: 2025-03-28 06:39:14
Score: 0.5
Natty:
Report link

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,

Reasons:
  • Blacklisted phrase (1): Regards
  • Long answer (-0.5):
  • Has code block (-0.5):
  • Low reputation (0.5):
Posted by: Tatachiblob