'Laravel 9 - Testing Expected response status code [201] but received 403

I use "WithoutMiddleware" to through Passport + Spatie permission Middleware but it not working.

use Illuminate\Foundation\Testing\WithoutMiddleware;

class BlueprintTest extends TestCase
{
use WithoutMiddleware; // use this trait

    public function test_store_success()
    {
        $this->withoutMiddleware();
        $response = $this
            ->withHeaders(['Accept' => 'application/json'])
            ->json('POST', '/api/v1/blueprints',$this->row_data);
    
        $response->assertStatus(201);
        $response->assertJson(['data' => $this->row_data]);
    
    }

}

There was 1 failure:

  1. Tests\Feature\BlueprintTest::test_store_success Expected response status code [201] but received 403. Failed asserting that 201 is identical to 403.

my assert is status code "201"



Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source