Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
67 changes: 1 addition & 66 deletions src/Codeception/Module/Yii2.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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;

/**
Expand Down Expand Up @@ -207,7 +203,6 @@
* closeSessionOnRecreateApplication: bool,
* applicationClass: class-string<\yii\base\Application>|null
* }
* @phpstan-type SessionBackup array{cookie: array<mixed>, session: array<mixed>, headers: array<string, string>, clientContext: array{ cookieJar: CookieJar, history: History }}
* @phpstan-type ClientConfig array{
* configFile: string,
* responseCleanMethod: Yii2Connector::CLEAN_CLEAR|Yii2Connector::CLEAN_MANUAL|Yii2Connector::CLEAN_RECREATE,
Expand All @@ -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<Yii2Connector\FixturesStore>
Expand Down Expand Up @@ -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();
}
}
}