diff --git a/src/Codeception/Module/Yii2.php b/src/Codeception/Module/Yii2.php index 768c69a..0da51e5 100644 --- a/src/Codeception/Module/Yii2.php +++ b/src/Codeception/Module/Yii2.php @@ -13,14 +13,11 @@ use Codeception\Lib\Connector\Yii2\TransactionForcer; use Codeception\Lib\Framework; use Codeception\Lib\Interfaces\ActiveRecord; -use Codeception\Lib\Interfaces\MultiSession; use Codeception\Lib\Interfaces\PartedModule; use Codeception\TestInterface; use PHPUnit\Framework\Assert; use ReflectionClass; use RuntimeException; -use Symfony\Component\BrowserKit\CookieJar; -use Symfony\Component\BrowserKit\History; use Yii; use yii\base\Security; use yii\db\ActiveQueryInterface; @@ -29,7 +26,6 @@ use yii\mail\BaseMessage; use yii\mail\MessageInterface; use yii\test\Fixture; -use yii\web\Application as WebApplication; use yii\web\IdentityInterface; /** @@ -207,7 +203,6 @@ * closeSessionOnRecreateApplication: bool, * applicationClass: class-string<\yii\base\Application>|null * } - * @phpstan-type SessionBackup array{cookie: array, session: array, headers: array, clientContext: array{ cookieJar: CookieJar, history: History }} * @phpstan-type ClientConfig array{ * configFile: string, * responseCleanMethod: Yii2Connector::CLEAN_CLEAR|Yii2Connector::CLEAN_MANUAL|Yii2Connector::CLEAN_RECREATE, @@ -218,7 +213,7 @@ * applicationClass: class-string<\yii\base\Application>|null * } */ -final class Yii2 extends Framework implements ActiveRecord, MultiSession, PartedModule +final class Yii2 extends Framework implements ActiveRecord, PartedModule { /** * @var list @@ -886,64 +881,4 @@ public function _afterSuite(): void $_SERVER = $this->server; } - - /** - * Initialize an empty session. Implements MultiSession. - */ - public function _initializeSession(): void - { - $this->getClient()->restart(); - $this->headers = []; - $_SESSION = []; - $_COOKIE = []; - } - - /** - * Return the session content for future restoring. Implements MultiSession. - * - * @return SessionBackup - */ - public function _backupSession(): array - { - if (Yii::$app instanceof WebApplication && Yii::$app->has('session', true) && Yii::$app->session->useCustomStorage) { - throw new ModuleException($this, "Yii2 MultiSession only supports the default session backend."); - } - return [ - 'clientContext' => $this->getClient()->getContext(), - 'headers' => $this->headers, - // @phpstan-ignore nullCoalesce.variable - 'cookie' => $_COOKIE ?? [], - 'session' => $_SESSION ?? [], - ]; - } - - /** - * Restore a session. Implements MultiSession. - * - * @param SessionBackup $session output of _backupSession() - */ - public function _loadSession($session): void - { - $this->getClient()->setContext($session['clientContext']); - $this->headers = $session['headers']; - $_SESSION = $session['session']; - $_COOKIE = $session['cookie']; - $app = Yii::$app; - if ($app?->has('user', true)) { - $definitions = $app->getComponents(); - $app->set('user', $definitions['user']); - } - } - - /** - * Close and dump a session. Implements MultiSession. - * - * @param mixed $session - */ - public function _closeSession($session = null): void - { - if (! $session) { - $this->_initializeSession(); - } - } }