Search code examples
laravelunit-testingcartalyst-sentinel

How can I do equivalent to actingAs() when not using Laravel Auth


All documentation that I have found refers to the Laravel helper actingAs() but this requires me to be using Laravel's native Auth package and I'm using Cartalyst's Sentinel and so can't use actingAs().

Has anyone found a way around this?


Solution

  • You can use the login method of Sentinel facade.

    $user = Sentinel::getUserById(1);
    $rememberMe = true;
    Sentinel::login($user, $rememberMe);
    

    You can also use setUser method of Sentinel facade. Note this doesn't log the user in.

    $user = Sentinel::getUserById(1);
    Sentinel::setUser($user);