Skip to content

Instantly share code, notes, and snippets.

@macedd
Created November 8, 2015 16:07
Show Gist options
  • Save macedd/e87c53842e2f62296a44 to your computer and use it in GitHub Desktop.
Save macedd/e87c53842e2f62296a44 to your computer and use it in GitHub Desktop.
Laravel Persist Test Session ID Between Controller Calls
<?php
class TestCase extends Laravel\Lumen\Testing\TestCase
{
/**
* Inject session ID into request, so api can persist on session
*/
public function call($method, $uri, $parameters = [], $cookies = [], $files = [], $server = [], $content = null)
{
$session_id = session()->getId();
$session_cookie = [session()->getName() => $session_id];
// set session_id cookie for persistent test calls
$cookies = array_merge($cookies, $session_cookie);
parent::call($method, $uri, $parameters, $cookies, $files, $server, $content);
}
}
@reynoldspaul
Copy link

This is awesome! Thanks

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment