Skip to content

Instantly share code, notes, and snippets.

@dimitri-koenig
Created September 18, 2016 15:11
Show Gist options
  • Save dimitri-koenig/43b543044359b67faeccb63bca97f207 to your computer and use it in GitHub Desktop.
Save dimitri-koenig/43b543044359b67faeccb63bca97f207 to your computer and use it in GitHub Desktop.
Behat Laravel Login As
<?php
function iAmLoggedIn()
{
// Destroy the previous session
if (Session::isStarted())
{
Session::regenerate(true);
}
else
{
Session::start();
}
Auth::login($this->user);
PHPUnit::assertTrue(Auth::check(), 'User is not logged in');
Session::save();
// Get the session identifier for the cookie
$encryptedSessionId = Crypt::encrypt(Session::getId());
$cookieName = Session::getName();
// Set the cookie
$minkSession = $this->getSession();
$minkSession->setCookie($cookieName, $encryptedSessionId);
$this->reload();
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment