-
Notifications
You must be signed in to change notification settings - Fork 38
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Fix parallel sessions with $I->haveFriend()
when no session is active
#91
Fix parallel sessions with $I->haveFriend()
when no session is active
#91
Conversation
I'm a bit confused though. This would resolve the exception for sure, but in your specific test case it will not work as expected. As far as I can tell the code should work for custom storage backends, any reason why you explicitly check for it and exclude it? |
I'm testing a REST application with enableSession set to false;
In my tests, I set a Bearer token to login as a specific user. I can now use this like this (simplified).
The |
Hmm, but if you are not really using sessions, why even use the friend workflow? $I->haveHttpHeader('Content-Type', 'application/json');
$I->setUpAuthentication('admin');
// make calls as admin
$I->setUpAuthentication('user');
// make calls as user This would work just as well right? I'm happy merging this btw, but I feel it's not very descriptive of what's happening. Since there is actually no session stuff and I'm pretty sure that even outside the In big caps my expectation of what'll happen: $I->haveHttpHeader('Content-Type', 'application/json');
$I->setUpAuthentication('admin');
// YOU ARE NOW ADMIN
$friend = $I->haveFriend('friend');
$friend->does(function (FunctionalTester $I) {
$I->haveHttpHeader('Content-Type', 'application/json');
$I->setUpAuthentication('user');
// YOU ARE NOW USER
});
// YOU ARE STILL USER |
Hmm, it actually works as expected. I'm using another token inside the closure. I suppose inside the closure, there is a new FunctionalTester instance with fresh empty headers. Some (simplified) debug log:
|
Ah, of course; the backup session function not only backs up the session but also the client context and headers: /**
* Return the session content for future restoring. Implements MultiSession.
* @return array backup data
*/
public function _backupSession(): array
{
if (isset(Yii::$app) && Yii::$app->session->useCustomStorage) {
throw new ModuleException($this, "Yii2 MultiSession only supports the default session backend.");
}
return [
'clientContext' => $this->client->getContext(),
'headers' => $this->headers,
'cookie' => isset($_COOKIE) ? $_COOKIE : [],
'session' => isset($_SESSION) ? $_SESSION : [],
];
} |
@samdark can you trigger / do a release? It's not automated and I don't know the release process. |
When using
$I->haveFriend()
, my tests would fail with the following error.This is because the code in
_backupSession()
didn't check if we actually have aYii::$app->session
before accessingYii::$app->session->useCustomStorage
.This PR fixes this and allows me to run my tests.
See #2 and #3