Skip to content

Commit

Permalink
add unit test for Yii::log()
Browse files Browse the repository at this point in the history
  • Loading branch information
klimov-paul committed Jul 19, 2023
1 parent 6ac2dc7 commit bfb4c71
Show file tree
Hide file tree
Showing 2 changed files with 27 additions and 0 deletions.
22 changes: 22 additions & 0 deletions tests/LoggerTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@

use CLogger;
use Psr\Log\LogLevel;
use Yii;
use yii1tech\psr\log\Logger;
use yii1tech\psr\log\test\support\ArrayLogger;

Expand Down Expand Up @@ -77,6 +78,27 @@ public function testWritePsrLog(): void
);
}

/**
* @depends testWritePsrLog
*/
public function testYiiLogFacade(): void
{
$psrLogger = new ArrayLogger();

$logger = (new Logger())
->setPsrLogger($psrLogger);

Yii::setLogger($logger);

Yii::log('test message', LogLevel::INFO, ['category' => 'context-category']);

$logs = $psrLogger->flush();
$this->assertFalse(empty($logs[0]));
$this->assertSame(LogLevel::INFO, $logs[0]['level']);
$this->assertSame('test message', $logs[0]['message']);
$this->assertSame(['category' => 'context-category'], $logs[0]['context']);
}

public function testWriteYiiLog(): void
{
$logger = (new Logger())
Expand Down
5 changes: 5 additions & 0 deletions tests/TestCase.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
namespace yii1tech\psr\log\test;

use CConsoleApplication;
use CLogger;
use CMap;
use Yii;

Expand All @@ -15,6 +16,8 @@ protected function setUp(): void
{
parent::setUp();

Yii::setLogger(new CLogger());

$this->mockApplication();
}

Expand All @@ -24,6 +27,8 @@ protected function setUp(): void
protected function tearDown(): void
{
$this->destroyApplication();

Yii::setLogger(null);
}

/**
Expand Down

0 comments on commit bfb4c71

Please sign in to comment.