14
14
use Codeception \Lib \Framework ;
15
15
use Codeception \Lib \Interfaces \ActiveRecord ;
16
16
use Codeception \Lib \Interfaces \PartedModule ;
17
+ use Codeception \Lib \ModuleContainer ;
17
18
use Codeception \TestInterface ;
18
19
use Exception ;
19
20
use PHPUnit \Framework \Assert ;
@@ -247,7 +248,7 @@ final class Yii2 extends Framework implements ActiveRecord, PartedModule
247
248
/**
248
249
* Helper to force database transaction
249
250
*/
250
- private TransactionForcer $ transactionForcer ;
251
+ private null | TransactionForcer $ transactionForcer ;
251
252
252
253
/**
253
254
* @var array<mixed> The contents of upon initialization of this object.
@@ -269,6 +270,14 @@ private function getClient(): Yii2Connector
269
270
return $ this ->client ;
270
271
}
271
272
273
+ public function __construct (ModuleContainer $ moduleContainer , ?array $ config = null )
274
+ {
275
+ parent ::__construct ($ moduleContainer , $ config );
276
+ $ this ->connectionWatcher = new ConnectionWatcher ();
277
+ $ this ->connectionWatcher ->start ();
278
+ }
279
+
280
+
272
281
public function _initialize (): void
273
282
{
274
283
if ($ this ->config ['transaction ' ] === null ) {
@@ -393,9 +402,6 @@ public function _before(TestInterface $test): void
393
402
$ this ->yiiLogger = new Yii2Connector \Logger ();
394
403
$ this ->getClient ()->startApp ($ this ->yiiLogger );
395
404
396
- $ this ->connectionWatcher = new ConnectionWatcher ();
397
- $ this ->connectionWatcher ->start ();
398
-
399
405
// load fixtures before db transaction
400
406
if ($ test instanceof \Codeception \Test \Cest) {
401
407
$ this ->loadFixtures ($ test ->getTestInstance ());
@@ -447,9 +453,7 @@ public function _after(TestInterface $test): void
447
453
$ this ->getClient ()->resetApplication ();
448
454
449
455
if (isset ($ this ->connectionWatcher )) {
450
- $ this ->connectionWatcher ->stop ();
451
456
$ this ->connectionWatcher ->closeAll ();
452
- unset($ this ->connectionWatcher );
453
457
}
454
458
455
459
parent ::_after ($ test );
0 commit comments