0

I am testing a Laravel 5.1 page that requires the user to be logged in. My project uses the Cartalyst/Sentinel packing for authentication.

I tried this but I doesn't recognize that the user is logged in.

public function testPageWithLogin()
{
    $user = Sentinel::findById(2);

    $this->actingAs($user)
         ->withSession([])
         ->visit('/page')
         ->dontSee('Whoops')
         ->dontSee('login');
}

What can I do so that the user will be seen as logged in?

cw24
  • 1,613
  • 2
  • 22
  • 31

1 Answers1

1

I forgot to log the user in using the Sentinel::login method. The user was legit just not seen as logged in.

This is the way it should have been done.

public function testPageWithLogin()
{
    $user = Sentinel::findById(2);
    Sentinel::login($user);

    $this->actingAs($user)
         ->withSession([])
         ->visit('/page')
         ->dontSee('Whoops')
         ->dontSee('login');
}
cw24
  • 1,613
  • 2
  • 22
  • 31
  • 1
    Sentinel's User model must implement Authenticatable Contract: `..\TestCase::actingAs() must be an instance of Illuminate\Contracts\Auth\Authenticatable` – Vladimir Vukanac Feb 08 '18 at 14:48