1414use Codeception \Lib \Framework ;
1515use Codeception \Lib \Interfaces \ActiveRecord ;
1616use Codeception \Lib \Interfaces \PartedModule ;
17+ use Codeception \Lib \ModuleContainer ;
1718use Codeception \TestInterface ;
1819use Exception ;
1920use PHPUnit \Framework \Assert ;
@@ -247,7 +248,7 @@ final class Yii2 extends Framework implements ActiveRecord, PartedModule
247248 /**
248249 * Helper to force database transaction
249250 */
250- private TransactionForcer $ transactionForcer ;
251+ private null | TransactionForcer $ transactionForcer ;
251252
252253 /**
253254 * @var array<mixed> The contents of upon initialization of this object.
@@ -269,6 +270,14 @@ private function getClient(): Yii2Connector
269270 return $ this ->client ;
270271 }
271272
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+
272281 public function _initialize (): void
273282 {
274283 if ($ this ->config ['transaction ' ] === null ) {
@@ -393,9 +402,6 @@ public function _before(TestInterface $test): void
393402 $ this ->yiiLogger = new Yii2Connector \Logger ();
394403 $ this ->getClient ()->startApp ($ this ->yiiLogger );
395404
396- $ this ->connectionWatcher = new ConnectionWatcher ();
397- $ this ->connectionWatcher ->start ();
398-
399405 // load fixtures before db transaction
400406 if ($ test instanceof \Codeception \Test \Cest) {
401407 $ this ->loadFixtures ($ test ->getTestInstance ());
@@ -447,9 +453,7 @@ public function _after(TestInterface $test): void
447453 $ this ->getClient ()->resetApplication ();
448454
449455 if (isset ($ this ->connectionWatcher )) {
450- $ this ->connectionWatcher ->stop ();
451456 $ this ->connectionWatcher ->closeAll ();
452- unset($ this ->connectionWatcher );
453457 }
454458
455459 parent ::_after ($ test );
0 commit comments