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

Refactor RotatingFileLoggerTest.php for log level functionality. #19

Merged
merged 2 commits into from
Sep 30, 2024
Merged
Changes from all 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
83 changes: 48 additions & 35 deletions tests/Unit/Logger/RotatingFileLoggerTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,51 +4,66 @@
use Seatplus\EsiClient\EsiConfiguration;
use Seatplus\EsiClient\Log\RotatingFileLogger;

describe('log anything above info level', function () {
beforeEach(function () {
// Set the file cache path in the config singleton
$this->root = vfsStream::setup('logs');
EsiConfiguration::getInstance(
logfile_location: $this->root->url(),
logger_level: \Monolog\Level::Info->value
);
beforeEach(function () {
EsiConfiguration::resetInstance();
});

$this->logger = new RotatingFileLogger;
afterEach(function () {
EsiConfiguration::resetInstance();
});

// Shitty hack to get the filename to expect. Format: esi-client-2018-05-06.log
$this->logfile_name = 'esi-client-'.date('Y-m-d').'.log';
});
it('writes error log', function () {
$root = vfsStream::setup('logs');

afterEach(function () {
EsiConfiguration::resetInstance();
});
EsiConfiguration::getInstance(
logfile_location: $root->url(),
logger_level: \Monolog\Level::Debug->value
);
$logger = new RotatingFileLogger;

it('writes info log', function () {
$this->logger->log('foo');
$logfile_content = $this->root->getChild($this->logfile_name)->getContent();
$logger->error('foo');
$logfile_name = 'esi-client-'.date('Y-m-d').'.log';

expect($logfile_content)->toContain('esi-client.INFO: foo');
});
$logfile_content = $root->getChild($logfile_name)->getContent();

it('writes warning log', function () {
$this->logger->warning('foo');
$logfile_content = $this->root->getChild($this->logfile_name)->getContent();
expect($logfile_content)->toContain('esi-client.ERROR: foo');
});

expect($logfile_content)->toContain('esi-client.WARNING: foo');
});
it('writes warning log', function () {
$root = vfsStream::setup('logs');

EsiConfiguration::getInstance(
logfile_location: $root->url(),
logger_level: \Monolog\Level::Debug->value
);
$logger = new RotatingFileLogger;

it('writes error log', function () {
$this->logger->error('foo');
$logfile_content = $this->root->getChild($this->logfile_name)->getContent();
$logger->warning('foo');
$logfile_name = 'esi-client-'.date('Y-m-d').'.log';

expect($logfile_content)->toContain('esi-client.ERROR: foo');
});
$logfile_content = $root->getChild($logfile_name)->getContent();

expect($logfile_content)->toContain('esi-client.WARNING: foo');
});

it('writes debug log', function () {
//Configuration::getInstance()->logger_level = Logger::DEBUG;
EsiConfiguration::resetInstance();
it('writes info log', function () {
$root = vfsStream::setup('logs');

EsiConfiguration::getInstance(
logfile_location: $root->url(),
logger_level: \Monolog\Level::Debug->value
);
$logger = new RotatingFileLogger;

$logger->log('foo');
$logfile_name = 'esi-client-'.date('Y-m-d').'.log';

$logfile_content = $root->getChild($logfile_name)->getContent();

expect($logfile_content)->toContain('esi-client.INFO: foo');
});

it('writes debug log', function () {
$root = vfsStream::setup('logs');

EsiConfiguration::getInstance(
Expand All @@ -63,6 +78,4 @@
$logfile_content = $root->getChild($logfile_name)->getContent();

expect($logfile_content)->toContain('esi-client.DEBUG: foo');

EsiConfiguration::resetInstance();
});
Loading