This is because you must have the respective route wrapped in an auth middleware...
For that you need to use
$this->actingAs(User::factory()))
Before hitting the ' resource' route in the test
Summer Sale! All accounts are 50% off this week.
I'm taking my first steps into testing and am following the Birdboard TDD tutorial with a few changes due to L9 instead of L5.7
I have a Test I made using artisan make:test ResourcesTest and in it I have:
/** @test */
public function a_user_can_create_a_resource()
{
$this->withoutExceptionHandling();
$attributes = [
'name' => $this->faker->sentence,
];
$response = $this->post('/resources', $attributes);
$response->assertStatus(200);
$this->assertDatabaseHas('resources', $attributes);
}
I have built the route, db migration, model and controller and can see it all working but when I post using Postman I get a Page Expired error as I'm not providing CSRF.
When I try and run my test I get the following error:
Illuminate\Auth\Access\AuthorizationException
This action is unauthorized.
I've modified PHPUNIT.xml. accordingly but I'm still stumped!
<env name="APP_ENV" value="testing"/>
<env name="DB_CONNECTION" value="sqlite"/>
<env name="DB_DATABASE" value=":memory:"/>
Please or to participate in this conversation.