Skip to content

Commit 4c4135d

Browse files
SlamdunkSamMousa
authored andcommitted
[Yii2] Allow to preserve session with recreateApplication enabled (#5630)
1 parent 9ce89c8 commit 4c4135d

File tree

2 files changed

+17
-5
lines changed

2 files changed

+17
-5
lines changed

src/Codeception/Lib/Connector/Yii2.php

Lines changed: 13 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -80,6 +80,11 @@ class Yii2 extends Client
8080
*/
8181
public $recreateApplication = false;
8282

83+
/**
84+
* @var bool whether to close the session in between requests inside a single test, if recreateApplication is set to true
85+
*/
86+
public $closeSessionOnRecreateApplication = true;
87+
8388

8489
private $emails = [];
8590

@@ -96,10 +101,15 @@ public function getApplication()
96101
return Yii::$app;
97102
}
98103

99-
public function resetApplication()
104+
/**
105+
* @param bool $closeSession
106+
*/
107+
public function resetApplication($closeSession = true)
100108
{
101109
codecept_debug('Destroying application');
102-
$this->closeSession();
110+
if (true === $closeSession) {
111+
$this->closeSession();
112+
}
103113
Yii::$app = null;
104114
\yii\web\UploadedFile::reset();
105115
if (method_exists(\yii\base\Event::className(), 'offAll')) {
@@ -542,7 +552,7 @@ protected function resetRequest(Application $app)
542552
protected function beforeRequest()
543553
{
544554
if ($this->recreateApplication) {
545-
$this->resetApplication();
555+
$this->resetApplication($this->closeSessionOnRecreateApplication);
546556
return;
547557
}
548558

src/Codeception/Module/Yii2.php

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -46,8 +46,9 @@
4646
* * `recreateComponents` - (default: []) Some components change their state making them unsuitable for processing multiple requests. In production this is usually
4747
* not a problem since web apps tend to die and start over after each request. This allows you to list application components that need to be recreated before each request.
4848
* As a consequence, any components specified here should not be changed inside a test since those changes will get regarded.
49-
* You can use this module by setting params in your functional.suite.yml:
5049
* * `recreateApplication` - (default: false) whether to recreate the whole application before each request
50+
* * `closeSessionOnRecreateApplication` - (default: true) whether to close the session in between requests inside a single test,
51+
* * if recreateApplication is set to true
5152
* You can use this module by setting params in your functional.suite.yml:
5253
* ```yaml
5354
* actor: FunctionalTester
@@ -162,7 +163,8 @@ class Yii2 extends Framework implements ActiveRecord, PartedModule
162163
'responseCleanMethod' => Yii2Connector::CLEAN_CLEAR,
163164
'requestCleanMethod' => Yii2Connector::CLEAN_RECREATE,
164165
'recreateComponents' => [],
165-
'recreateApplication' => false
166+
'recreateApplication' => false,
167+
'closeSessionOnRecreateApplication' => true,
166168
];
167169

168170
protected $requiredFields = ['configFile'];

0 commit comments

Comments
 (0)