Skip to content

Commit 1188aa1

Browse files
authored
Merge pull request #132 from Codeception/fix-possibly-uninit-yiilogger
fix: fixes #131 yiilogger may not be initialized in _failed
2 parents 956c3bb + f3ce1ca commit 1188aa1

File tree

3 files changed

+5
-10
lines changed

3 files changed

+5
-10
lines changed

phpstan-baseline.neon

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1698,12 +1698,6 @@ parameters:
16981698
count: 1
16991699
path: tests/cases/pageCacheHeaderAlreadySent/controllers/UserController.php
17001700

1701-
-
1702-
message: '#^Method app\\pageCacheHeaderAlreadySent\\controllers\\UserController\:\:behaviors\(\) return type has no value type specified in iterable type array\.$#'
1703-
identifier: missingType.iterableValue
1704-
count: 1
1705-
path: tests/cases/pageCacheHeaderAlreadySent/controllers/UserController.php
1706-
17071701
-
17081702
message: '#^Method PageCest\:\:testCache\(\) has no return type specified\.$#'
17091703
identifier: missingType.return

src/Codeception/Lib/Connector/Yii2.php

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -305,6 +305,7 @@ public function startApp(?\yii\log\Logger $logger = null): void
305305
self::MAIL_IGNORE => null// Do nothing
306306
};
307307

308+
// @phpstan-ignore argument.templateType
308309
$app = Yii::createObject($config);
309310
if (! $app instanceof \yii\base\Application) {
310311
throw new ModuleConfigException($this, "Failed to initialize Yii2 app");

src/Codeception/Module/Yii2.php

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -256,7 +256,7 @@ final class Yii2 extends Framework implements ActiveRecord, PartedModule
256256
*/
257257
private array $server;
258258

259-
private Logger $yiiLogger;
259+
private null|Logger $yiiLogger = null;
260260

261261
private function getClient(): Yii2Connector
262262
{
@@ -292,7 +292,7 @@ protected function onReconfigure(): void
292292
$this->getClient()->resetApplication();
293293
$this->validateConfig();
294294
$this->configureClient($this->config);
295-
$this->yiiLogger->getAndClearLog();
295+
$this->yiiLogger?->getAndClearLog();
296296
$this->getClient()->startApp($this->yiiLogger);
297297
}
298298

@@ -460,8 +460,8 @@ public function _after(TestInterface $test): void
460460
*/
461461
public function _failed(TestInterface $test, $fail): void
462462
{
463-
$log = $this->yiiLogger->getAndClearLog();
464-
if ($log !== '') {
463+
$log = $this->yiiLogger?->getAndClearLog();
464+
if (isset($log) && $log !== '') {
465465
$test->getMetadata()->addReport('yii-log', $log);
466466
}
467467

0 commit comments

Comments
 (0)