Skip to content

Commit

Permalink
Fixing tests
Browse files Browse the repository at this point in the history
  • Loading branch information
hiqsol committed Jan 1, 2019
1 parent 5d9f8b6 commit 7165fc9
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 9 deletions.
5 changes: 3 additions & 2 deletions src/migrations/m141106_185632_log_init.php
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
use yii\exceptions\InvalidConfigException;
use yii\db\Migration;
use yii\log\DbTarget;
use yii\helpers\Yii;

/**
* Initializes log table.
Expand All @@ -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,
Expand Down
17 changes: 10 additions & 7 deletions tests/unit/DbTargetTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;

/**
Expand Down Expand Up @@ -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,
],
],
],
],
Expand Down

0 comments on commit 7165fc9

Please # to comment.