Ultra Quick Tip: Getting Session Data in a Codeception test using Laravel

You are currently viewing the Mobile Optimized version (AMP), some features may be missing or may not work as expected. Open Full Version.

If you are using Codeception for writing your tests for your Laravel applications and you need to get some value stored in the Session, then the following piece of code can help you do that:

$service = $I->grabService('session');
$phone_request = $service->driver()->get('phone-request');

The “phone-request” is a key in the session.


Getting the session data isn’t directly mentioned in the Codeception docs, but based on how things were working for other services I figured that the above code should work and it did!

Codeception is a pretty neat testing library, definitely recommended for your next project.