ActingAs Not working. I'm trying to test if user can see dashboard after login however it works perfectly fine in browser but when I run phpunit. I get status code 302. It redirect to login page. I'm using sqlite for testing
<php>
<env name="APP_ENV" value="testing"/>
<env name="DB_CONNECTION" value="sqlite" />
<env name="DB_DATABASE" value=":memory:"/>
<env name="CACHE_DRIVER" value="array"/>
<env name="SESSION_DRIVER" value="array"/>
<env name="QUEUE_DRIVER" value="sync"/>
</php>
and in this is my test functions
/** @test */
public function a_authenticated_admin_can_see_dashboard()
{
$admin = factory('App\Admin')->create(['password' => 'secret']);
$this->actingAs($admin)
->get(route('admin.index'))
->assertSee('Admin Dashboard');
}
Please help. Thank you.
Ohh sorry. I'm an idiot. I'm using custom guard i changed my code to below code.
Issue was, i'm using custom guard for admin user. When I inspected actingAs method then I saw it uses default guard to login if nothing provided.
/** @test */
public function a_authenticated_admin_can_see_dashboard()
{
$admin = factory('App\Admin')->create(['password' => 'secret']);
$this->actingAs($admin, 'admin')
->get(route('admin.index'))
->assertSee('DASHBOARD');
}
Thanks
Please sign in or create an account to participate in this conversation.