From b480bf18befdc8ede138f2f3a6b09a8989d11cb9 Mon Sep 17 00:00:00 2001 From: Sam Mousa Date: Thu, 29 May 2025 15:28:38 +0200 Subject: [PATCH 1/3] fix: fixes #131 yiilogger may not be initialized in _failed --- src/Codeception/Module/Yii2.php | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/Codeception/Module/Yii2.php b/src/Codeception/Module/Yii2.php index 30f3372..96cfa41 100644 --- a/src/Codeception/Module/Yii2.php +++ b/src/Codeception/Module/Yii2.php @@ -460,8 +460,8 @@ public function _after(TestInterface $test): void */ public function _failed(TestInterface $test, $fail): void { - $log = $this->yiiLogger->getAndClearLog(); - if ($log !== '') { + $log = $this->yiiLogger?->getAndClearLog(); + if (isset($log) && $log !== '') { $test->getMetadata()->addReport('yii-log', $log); } From 9e0ea245e852572344cde1fccde093052194a683 Mon Sep 17 00:00:00 2001 From: Sam Mousa Date: Fri, 30 May 2025 10:06:24 +0200 Subject: [PATCH 2/3] chore: make logger explicitly nullable --- src/Codeception/Module/Yii2.php | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/Codeception/Module/Yii2.php b/src/Codeception/Module/Yii2.php index 96cfa41..3a19cf8 100644 --- a/src/Codeception/Module/Yii2.php +++ b/src/Codeception/Module/Yii2.php @@ -256,7 +256,7 @@ final class Yii2 extends Framework implements ActiveRecord, PartedModule */ private array $server; - private Logger $yiiLogger; + private null|Logger $yiiLogger = null; private function getClient(): Yii2Connector { @@ -292,7 +292,7 @@ protected function onReconfigure(): void $this->getClient()->resetApplication(); $this->validateConfig(); $this->configureClient($this->config); - $this->yiiLogger->getAndClearLog(); + $this->yiiLogger?->getAndClearLog(); $this->getClient()->startApp($this->yiiLogger); } From f3ce1cae1ec4d3ddd0c2f235191e3ec378406418 Mon Sep 17 00:00:00 2001 From: Sam Mousa Date: Fri, 30 May 2025 10:22:05 +0200 Subject: [PATCH 3/3] chore: fixed SA errors due to phpstan update --- phpstan-baseline.neon | 6 ------ src/Codeception/Lib/Connector/Yii2.php | 1 + 2 files changed, 1 insertion(+), 6 deletions(-) diff --git a/phpstan-baseline.neon b/phpstan-baseline.neon index 7e2667d..01178ed 100644 --- a/phpstan-baseline.neon +++ b/phpstan-baseline.neon @@ -1698,12 +1698,6 @@ parameters: count: 1 path: tests/cases/pageCacheHeaderAlreadySent/controllers/UserController.php - - - message: '#^Method app\\pageCacheHeaderAlreadySent\\controllers\\UserController\:\:behaviors\(\) return type has no value type specified in iterable type array\.$#' - identifier: missingType.iterableValue - count: 1 - path: tests/cases/pageCacheHeaderAlreadySent/controllers/UserController.php - - message: '#^Method PageCest\:\:testCache\(\) has no return type specified\.$#' identifier: missingType.return diff --git a/src/Codeception/Lib/Connector/Yii2.php b/src/Codeception/Lib/Connector/Yii2.php index 206c924..379bfc1 100644 --- a/src/Codeception/Lib/Connector/Yii2.php +++ b/src/Codeception/Lib/Connector/Yii2.php @@ -305,6 +305,7 @@ public function startApp(?\yii\log\Logger $logger = null): void self::MAIL_IGNORE => null// Do nothing }; + // @phpstan-ignore argument.templateType $app = Yii::createObject($config); if (! $app instanceof \yii\base\Application) { throw new ModuleConfigException($this, "Failed to initialize Yii2 app");