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

Spread the love

Open Mobile 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.

Leave a Reply

Your email address will not be published. Required fields are marked *

%d bloggers like this: