From b616dc04ce0feba1dd23de8d75cafd05b7ce59eb Mon Sep 17 00:00:00 2001 From: Herpaderp Aldent Date: Mon, 30 Sep 2024 21:44:17 +0200 Subject: [PATCH 1/2] Refactor RotatingFileLoggerTest.php for log level functionality. --- tests/Unit/Logger/RotatingFileLoggerTest.php | 84 ++++++++++++-------- 1 file changed, 49 insertions(+), 35 deletions(-) diff --git a/tests/Unit/Logger/RotatingFileLoggerTest.php b/tests/Unit/Logger/RotatingFileLoggerTest.php index 23f08d3..f4f93ee 100644 --- a/tests/Unit/Logger/RotatingFileLoggerTest.php +++ b/tests/Unit/Logger/RotatingFileLoggerTest.php @@ -4,51 +4,67 @@ 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(); +}); + +afterEach(function() { + EsiConfiguration::resetInstance(); +}); + +it('writes error log', function () { + $root = vfsStream::setup('logs'); + + EsiConfiguration::getInstance( + logfile_location: $root->url(), + logger_level: \Monolog\Level::Debug->value + ); + $logger = new RotatingFileLogger; + + $logger->error('foo'); + $logfile_name = 'esi-client-'.date('Y-m-d').'.log'; + + $logfile_content = $root->getChild($logfile_name)->getContent(); + + expect($logfile_content)->toContain('esi-client.ERROR: foo'); +}); + +it('writes warning log', function () { + $root = vfsStream::setup('logs'); - $this->logger = new RotatingFileLogger; + EsiConfiguration::getInstance( + logfile_location: $root->url(), + logger_level: \Monolog\Level::Debug->value + ); + $logger = new RotatingFileLogger; - // 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'; - }); + $logger->warning('foo'); + $logfile_name = 'esi-client-'.date('Y-m-d').'.log'; - afterEach(function () { - EsiConfiguration::resetInstance(); - }); + $logfile_content = $root->getChild($logfile_name)->getContent(); - it('writes info log', function () { - $this->logger->log('foo'); - $logfile_content = $this->root->getChild($this->logfile_name)->getContent(); + expect($logfile_content)->toContain('esi-client.WARNING: foo'); +}); - expect($logfile_content)->toContain('esi-client.INFO: foo'); - }); +it('writes info log', function () { + $root = vfsStream::setup('logs'); - it('writes warning log', function () { - $this->logger->warning('foo'); - $logfile_content = $this->root->getChild($this->logfile_name)->getContent(); + EsiConfiguration::getInstance( + logfile_location: $root->url(), + logger_level: \Monolog\Level::Debug->value + ); + $logger = new RotatingFileLogger; - expect($logfile_content)->toContain('esi-client.WARNING: foo'); - }); + $logger->log('foo'); + $logfile_name = 'esi-client-'.date('Y-m-d').'.log'; - it('writes error log', function () { - $this->logger->error('foo'); - $logfile_content = $this->root->getChild($this->logfile_name)->getContent(); + $logfile_content = $root->getChild($logfile_name)->getContent(); - expect($logfile_content)->toContain('esi-client.ERROR: foo'); - }); + expect($logfile_content)->toContain('esi-client.INFO: foo'); }); -it('writes debug log', function () { - //Configuration::getInstance()->logger_level = Logger::DEBUG; - EsiConfiguration::resetInstance(); +it('writes debug log', function () { $root = vfsStream::setup('logs'); EsiConfiguration::getInstance( @@ -63,6 +79,4 @@ $logfile_content = $root->getChild($logfile_name)->getContent(); expect($logfile_content)->toContain('esi-client.DEBUG: foo'); - - EsiConfiguration::resetInstance(); }); From ca502f0497e47d87addf9f9aecc6cac8c67b67d4 Mon Sep 17 00:00:00 2001 From: Herpaderp Aldent Date: Mon, 30 Sep 2024 21:48:58 +0200 Subject: [PATCH 2/2] lint --- tests/Unit/Logger/RotatingFileLoggerTest.php | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/tests/Unit/Logger/RotatingFileLoggerTest.php b/tests/Unit/Logger/RotatingFileLoggerTest.php index f4f93ee..9bcd47d 100644 --- a/tests/Unit/Logger/RotatingFileLoggerTest.php +++ b/tests/Unit/Logger/RotatingFileLoggerTest.php @@ -4,11 +4,11 @@ use Seatplus\EsiClient\EsiConfiguration; use Seatplus\EsiClient\Log\RotatingFileLogger; -beforeEach(function() { +beforeEach(function () { EsiConfiguration::resetInstance(); }); -afterEach(function() { +afterEach(function () { EsiConfiguration::resetInstance(); }); @@ -63,7 +63,6 @@ expect($logfile_content)->toContain('esi-client.INFO: foo'); }); - it('writes debug log', function () { $root = vfsStream::setup('logs');