From 12b6c4b3008c2df545c537943d4e38323cfc174e Mon Sep 17 00:00:00 2001 From: Asko Nõmm Date: Sun, 10 Nov 2024 22:28:03 +0200 Subject: Initial commit --- tests/Drivers/FileSystemDriverTest.php | 155 +++++++++++++++++++++++++++++++++ 1 file changed, 155 insertions(+) create mode 100644 tests/Drivers/FileSystemDriverTest.php (limited to 'tests/Drivers/FileSystemDriverTest.php') diff --git a/tests/Drivers/FileSystemDriverTest.php b/tests/Drivers/FileSystemDriverTest.php new file mode 100644 index 0000000..bb49042 --- /dev/null +++ b/tests/Drivers/FileSystemDriverTest.php @@ -0,0 +1,155 @@ +emergency('test'); + $lines = file(__DIR__ . '/logs/' . $date->format('Y-m-d') . '.log'); + $last_line = end($lines); + $full_date = $date->format('Y-m-d H:i:s'); + $this->assertStringContainsString("[{$full_date}] FileSystemDriverTest.EMERGENCY: test", $last_line); + } + + /** + * @throws \Exception + */ + public function testAlert(): void + { + $date = new DateTime(); + $loggr = new Loggr(new FileSystemDriver(__DIR__ . '/logs')); + $loggr->alert('test'); + $lines = file(__DIR__ . '/logs/' . $date->format('Y-m-d') . '.log'); + $last_line = end($lines); + $full_date = $date->format('Y-m-d H:i:s'); + $this->assertStringContainsString("[{$full_date}] FileSystemDriverTest.ALERT: test", $last_line); + } + + /** + * @throws \Exception + */ + public function testCritical(): void + { + $date = new DateTime(); + $loggr = new Loggr(new FileSystemDriver(__DIR__ . '/logs')); + $loggr->critical('test'); + $lines = file(__DIR__ . '/logs/' . $date->format('Y-m-d') . '.log'); + $last_line = end($lines); + $full_date = $date->format('Y-m-d H:i:s'); + $this->assertStringContainsString("[{$full_date}] FileSystemDriverTest.CRITICAL: test", $last_line); + } + + /** + * @throws \Exception + */ + public function testError(): void + { + $date = new DateTime(); + $loggr = new Loggr(new FileSystemDriver(__DIR__ . '/logs')); + $loggr->error('test'); + $lines = file(__DIR__ . '/logs/' . $date->format('Y-m-d') . '.log'); + $last_line = end($lines); + $full_date = $date->format('Y-m-d H:i:s'); + $this->assertStringContainsString("[{$full_date}] FileSystemDriverTest.ERROR: test", $last_line); + } + + /** + * @throws \Exception + */ + public function testWarning(): void + { + $date = new DateTime(); + $loggr = new Loggr(new FileSystemDriver(__DIR__ . '/logs')); + $loggr->warning('test'); + $lines = file(__DIR__ . '/logs/' . $date->format('Y-m-d') . '.log'); + $last_line = end($lines); + $full_date = $date->format('Y-m-d H:i:s'); + $this->assertStringContainsString("[{$full_date}] FileSystemDriverTest.WARNING: test", $last_line); + } + + /** + * @throws \Exception + */ + public function testNotice(): void + { + $date = new DateTime(); + $loggr = new Loggr(new FileSystemDriver(__DIR__ . '/logs')); + $loggr->notice('test'); + $lines = file(__DIR__ . '/logs/' . $date->format('Y-m-d') . '.log'); + $last_line = end($lines); + $full_date = $date->format('Y-m-d H:i:s'); + $this->assertStringContainsString("[{$full_date}] FileSystemDriverTest.NOTICE: test", $last_line); + } + + /** + * @throws \Exception + */ + public function testInfo(): void + { + $date = new DateTime(); + $loggr = new Loggr(new FileSystemDriver(__DIR__ . '/logs')); + $loggr->info('test'); + $lines = file(__DIR__ . '/logs/' . $date->format('Y-m-d') . '.log'); + $last_line = end($lines); + $full_date = $date->format('Y-m-d H:i:s'); + $this->assertStringContainsString("[{$full_date}] FileSystemDriverTest.INFO: test", $last_line); + } + + /** + * @throws \Exception + */ + public function testDebug(): void + { + $date = new DateTime(); + $loggr = new Loggr(new FileSystemDriver(__DIR__ . '/logs')); + $loggr->debug('test'); + $lines = file(__DIR__ . '/logs/' . $date->format('Y-m-d') . '.log'); + $last_line = end($lines); + $full_date = $date->format('Y-m-d H:i:s'); + $this->assertStringContainsString("[{$full_date}] FileSystemDriverTest.DEBUG: test", $last_line); + } + + /** + * @throws \Exception + */ + public function testMultipleEntries(): void + { + $date = new DateTime(); + $loggr = new Loggr(new FileSystemDriver(__DIR__ . '/logs')); + $loggr->emergency('test'); + $loggr->alert('test'); + $loggr->critical('test'); + $loggr->error('test'); + $loggr->warning('test'); + $loggr->notice('test'); + $loggr->info('test'); + $loggr->debug('test'); + + $lines = file(__DIR__ . '/logs/' . $date->format('Y-m-d') . '.log'); + $this->assertCount(8, $lines); + + $first_line = $lines[0]; + $last_line = end($lines); + $full_date = $date->format('Y-m-d H:i:s'); + $this->assertStringContainsString("[{$full_date}] FileSystemDriverTest.EMERGENCY: test", $first_line); + $this->assertStringContainsString("[{$full_date}] FileSystemDriverTest.DEBUG: test", $last_line); + } + + public function tearDown(): void + { + array_map('unlink', glob(__DIR__ . '/logs/*')); + rmdir(__DIR__ . '/logs'); + } +} \ No newline at end of file -- cgit v1.2.3