Created
November 8, 2015 16:07
-
-
Save macedd/e87c53842e2f62296a44 to your computer and use it in GitHub Desktop.
Laravel Persist Test Session ID Between Controller Calls
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?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); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
This is awesome! Thanks