susanBuck / e15-spring22

0 stars 0 forks source link

Question: Can Codeception access session data? #65

Closed archerdave closed 2 years ago

archerdave commented 2 years ago

Does Codeception have any access to the HTTP session data? For example, when a user logs in, the session gets certain pieces of data. Checking for this data could be useful in verifying a login. Perhaps in other cases as well. I saw that it can do some work with cookies, but I didn't see the session data mentioned.

susanBuck commented 2 years ago

You could do something like this...

In TestController add a method we’ll call meta that returns useful meta info (including session data) as json data:

public function meta(Request $request)
{
    return response()->json([
        'user' => $request->user(),
        'cookie' => $request->cookie(),
        'session' => $request->session()->all(),
    ]);
}

Then you can access it in tests like so:

$I->amOnPage('/test/meta');
$metaData = json_decode($I->grabPageSource(), true);
archerdave commented 2 years ago

Thanks, that makes sense.