diff --git a/src/migrations/m141106_185632_log_init.php b/src/migrations/m141106_185632_log_init.php index aff991af6..3167fe30a 100644 --- a/src/migrations/m141106_185632_log_init.php +++ b/src/migrations/m141106_185632_log_init.php @@ -8,6 +8,7 @@ use yii\exceptions\InvalidConfigException; use yii\db\Migration; use yii\log\DbTarget; +use yii\helpers\Yii; /** * Initializes log table. @@ -33,13 +34,13 @@ class m141106_185632_log_init extends Migration protected function getDbTargets() { if ($this->dbTargets === []) { - $logger = Yii::getLogger(); + $logger = Yii::getApp()->getLogger(); if (!$logger instanceof \yii\log\Logger) { throw new InvalidConfigException('You should configure "logger" to be instance of "\yii\log\Logger" before executing this migration.'); } $usedTargets = []; - foreach ($logger->targets as $target) { + foreach ($logger->getTargets() as $target) { if ($target instanceof DbTarget) { $currentTarget = [ $target->db, diff --git a/tests/unit/DbTargetTest.php b/tests/unit/DbTargetTest.php index 538dcf1b4..5bfc81a5c 100644 --- a/tests/unit/DbTargetTest.php +++ b/tests/unit/DbTargetTest.php @@ -10,10 +10,10 @@ use Psr\Log\LogLevel; use yii\helpers\Yii; use yii\console\ExitCode; +use yii\console\tests\unit\controllers\EchoMigrateController; use yii\db\Connection; use yii\db\Query; use yii\log\DbTarget; -use yiiunit\framework\console\controllers\EchoMigrateController; use yii\tests\TestCase; /** @@ -41,13 +41,16 @@ protected function runConsoleAction($route, $params = []) 'controllerMap' => [ 'migrate' => EchoMigrateController::class, ], - ], [ + ], null, [ 'logger' => [ - 'targets' => [ - 'db' => [ - '__class' => DbTarget::class, - 'levels' => [LogLevel::WARNING], - 'logTable' => self::$logTable, + '__class' => 'yii\\log\\Logger', + '__construct()' => [ + 'targets' => [ + 'db' => [ + '__class' => DbTarget::class, + 'levels' => [LogLevel::WARNING], + 'logTable' => self::$logTable, + ], ], ], ],