Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

test(logger/formatter/line): added test with a different line format #15401

Merged
merged 4 commits into from
Apr 19, 2021
Merged
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
52 changes: 51 additions & 1 deletion tests/unit/Logger/Logger/LogCest.php
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@
use Phalcon\Logger;
use Phalcon\Logger\Adapter\Stream;
use Phalcon\Logger\Adapter\Syslog;
use Phalcon\Logger\Formatter\Line;
use Psr\Log\LogLevel;
use UnitTester;

Expand All @@ -27,6 +28,9 @@ class LogCest
{
/**
* Tests Phalcon\Logger :: log()
*
* @author Phalcon Team <team@phalcon.io>
* @since 2019-10-21
*/
public function loggerLog(UnitTester $I)
{
Expand Down Expand Up @@ -88,6 +92,9 @@ public function loggerLog(UnitTester $I)

/**
* Tests Phalcon\Logger :: log() - logLevel
*
* @author Phalcon Team <team@phalcon.io>
* @since 2019-10-21
*/
public function loggerLogLogLevel(UnitTester $I)
{
Expand Down Expand Up @@ -166,6 +173,9 @@ public function loggerLogLogLevel(UnitTester $I)

/**
* Tests Phalcon\Logger :: log()
*
* @author Phalcon Team <team@phalcon.io>
* @since 2019-10-21
*/
public function loggerLogSyslog(UnitTester $I)
{
Expand All @@ -186,7 +196,9 @@ public function loggerLogSyslog(UnitTester $I)
/**
* Tests Phalcon\Logger :: log() - logLevel
*
* @issue #15214
* @author Phalcon Team <team@phalcon.io>
* @since 2020-12-09
* @issue #15214
*/
public function loggerLogLogLevelPsr(UnitTester $I)
{
Expand Down Expand Up @@ -218,4 +230,42 @@ public function loggerLogLogLevelPsr(UnitTester $I)
$adapter->close();
$I->safeDeleteFile($fileName);
}

/**
* Tests Phalcon\Logger :: log() - different line format
*
* @author Phalcon Team <team@phalcon.io>
* @since 2121-04-14
* @issue #15375
*/
public function loggerLogLogLevelDifferentLineFormat(UnitTester $I)
{
$I->wantToTest('Logger - log() - different line format');

$unique = uniqid();
$logPath = logsDir();
$fileName = $I->getNewFileName('log', 'log');
$format = '[%date%] [%type%] %message%';
$formatter = new Line($format);
$adapter = new Stream($logPath . $fileName);
$adapter->setFormatter($formatter);

$logger = new Logger(
'my-logger',
[
'one' => $adapter,
]
);

$logger->log(Logger::INFO, 'info message ' . $unique);

$I->amInPath($logPath);
$I->openFile($fileName);

$expected = '[info] info message ' . $unique;
$I->seeInThisFile($expected);

$adapter->close();
$I->safeDeleteFile($fileName);
}
}