Skip to content

Commit ed554e3

Browse files
authored
Merge pull request #124 from Codeception/remove-multi-session
Remove multi session
2 parents 3f8ffe0 + b4947b7 commit ed554e3

File tree

1 file changed

+1
-66
lines changed

1 file changed

+1
-66
lines changed

src/Codeception/Module/Yii2.php

Lines changed: 1 addition & 66 deletions
Original file line numberDiff line numberDiff line change
@@ -13,14 +13,11 @@
1313
use Codeception\Lib\Connector\Yii2\TransactionForcer;
1414
use Codeception\Lib\Framework;
1515
use Codeception\Lib\Interfaces\ActiveRecord;
16-
use Codeception\Lib\Interfaces\MultiSession;
1716
use Codeception\Lib\Interfaces\PartedModule;
1817
use Codeception\TestInterface;
1918
use PHPUnit\Framework\Assert;
2019
use ReflectionClass;
2120
use RuntimeException;
22-
use Symfony\Component\BrowserKit\CookieJar;
23-
use Symfony\Component\BrowserKit\History;
2421
use Yii;
2522
use yii\base\Security;
2623
use yii\db\ActiveQueryInterface;
@@ -29,7 +26,6 @@
2926
use yii\mail\BaseMessage;
3027
use yii\mail\MessageInterface;
3128
use yii\test\Fixture;
32-
use yii\web\Application as WebApplication;
3329
use yii\web\IdentityInterface;
3430

3531
/**
@@ -207,7 +203,6 @@
207203
* closeSessionOnRecreateApplication: bool,
208204
* applicationClass: class-string<\yii\base\Application>|null
209205
* }
210-
* @phpstan-type SessionBackup array{cookie: array<mixed>, session: array<mixed>, headers: array<string, string>, clientContext: array{ cookieJar: CookieJar, history: History }}
211206
* @phpstan-type ClientConfig array{
212207
* configFile: string,
213208
* responseCleanMethod: Yii2Connector::CLEAN_CLEAR|Yii2Connector::CLEAN_MANUAL|Yii2Connector::CLEAN_RECREATE,
@@ -218,7 +213,7 @@
218213
* applicationClass: class-string<\yii\base\Application>|null
219214
* }
220215
*/
221-
final class Yii2 extends Framework implements ActiveRecord, MultiSession, PartedModule
216+
final class Yii2 extends Framework implements ActiveRecord, PartedModule
222217
{
223218
/**
224219
* @var list<Yii2Connector\FixturesStore>
@@ -886,64 +881,4 @@ public function _afterSuite(): void
886881

887882
$_SERVER = $this->server;
888883
}
889-
890-
/**
891-
* Initialize an empty session. Implements MultiSession.
892-
*/
893-
public function _initializeSession(): void
894-
{
895-
$this->getClient()->restart();
896-
$this->headers = [];
897-
$_SESSION = [];
898-
$_COOKIE = [];
899-
}
900-
901-
/**
902-
* Return the session content for future restoring. Implements MultiSession.
903-
*
904-
* @return SessionBackup
905-
*/
906-
public function _backupSession(): array
907-
{
908-
if (Yii::$app instanceof WebApplication && Yii::$app->has('session', true) && Yii::$app->session->useCustomStorage) {
909-
throw new ModuleException($this, "Yii2 MultiSession only supports the default session backend.");
910-
}
911-
return [
912-
'clientContext' => $this->getClient()->getContext(),
913-
'headers' => $this->headers,
914-
// @phpstan-ignore nullCoalesce.variable
915-
'cookie' => $_COOKIE ?? [],
916-
'session' => $_SESSION ?? [],
917-
];
918-
}
919-
920-
/**
921-
* Restore a session. Implements MultiSession.
922-
*
923-
* @param SessionBackup $session output of _backupSession()
924-
*/
925-
public function _loadSession($session): void
926-
{
927-
$this->getClient()->setContext($session['clientContext']);
928-
$this->headers = $session['headers'];
929-
$_SESSION = $session['session'];
930-
$_COOKIE = $session['cookie'];
931-
$app = Yii::$app;
932-
if ($app?->has('user', true)) {
933-
$definitions = $app->getComponents();
934-
$app->set('user', $definitions['user']);
935-
}
936-
}
937-
938-
/**
939-
* Close and dump a session. Implements MultiSession.
940-
*
941-
* @param mixed $session
942-
*/
943-
public function _closeSession($session = null): void
944-
{
945-
if (! $session) {
946-
$this->_initializeSession();
947-
}
948-
}
949884
}

0 commit comments

Comments
 (0)