I am running the following test and something is not right:
public function testBasicTest()
{
$token = 'lFMcWnzCWxzP...nIPMF8UF...gbQKCO';
$token_fake = '';
$response = $this->withHeaders([
'Content-Type' => 'application/json',
'Accept' => 'application/json',
'Authorization' => 'Bearer '.$token,
])->get('/api');
$response->assertStatus(200);
$response->assertJson([]);
$response = $this->withHeaders([
'Content-Type' => 'application/json',
'Accept' => 'application/json',
'Authorization' => 'Bearer '.$token_fake,
])->get('/api');
$response->assertStatus(401);
}
because he answers me
Time: 00:00.087, Memory: 22.00 MB
There was 1 failure:
1) Tests\Feature\ExampleTest::testBasicTest
Expected status code 401 but received 200.
Failed asserting that 401 is identical to 200.
.../vendor/laravel/framework/src/Illuminate/Testing/TestResponse.php:186
.../tests/Feature/ExampleTest.php:32
if I test the api GET from insomnia it replies 401 if the token is incorrect or I don't put it. I don't understand why the last assert fails me.
$response->assertStatus(401);
I would expect 401 but it answers 201. I don't understand