From 246e5a24a5ceedf364e06bb13e0a26cf46ee9507 Mon Sep 17 00:00:00 2001 From: Asko Nõmm Date: Sun, 10 Nov 2024 22:49:52 +0200 Subject: Add phpunit.xml --- composer.json | 7 +- tests/Drivers/FileSystemDriverTest.php | 155 --------------------------------- tests/Drivers/OutputDriverTest.php | 99 --------------------- tests/FileSystemDriverTest.php | 152 ++++++++++++++++++++++++++++++++ tests/LoggrTest.php | 2 - tests/OutputDriverTest.php | 96 ++++++++++++++++++++ 6 files changed, 249 insertions(+), 262 deletions(-) delete mode 100644 tests/Drivers/FileSystemDriverTest.php delete mode 100644 tests/Drivers/OutputDriverTest.php create mode 100644 tests/FileSystemDriverTest.php create mode 100644 tests/OutputDriverTest.php diff --git a/composer.json b/composer.json index c5172f0..104a3f8 100644 --- a/composer.json +++ b/composer.json @@ -8,11 +8,6 @@ "Asko\\Loggr\\": "src/" } }, - "autoload-dev": { - "psr-4": { - "Asko\\Loggr\\Tests\\": "tests/" - } - }, "authors": [ { "name": "Asko Nomm", @@ -20,7 +15,7 @@ } ], "require": { - "php": "^8.3" + "php": ">=8.3" }, "require-dev": { "phpunit/phpunit": "11" diff --git a/tests/Drivers/FileSystemDriverTest.php b/tests/Drivers/FileSystemDriverTest.php deleted file mode 100644 index bb49042..0000000 --- a/tests/Drivers/FileSystemDriverTest.php +++ /dev/null @@ -1,155 +0,0 @@ -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 diff --git a/tests/Drivers/OutputDriverTest.php b/tests/Drivers/OutputDriverTest.php deleted file mode 100644 index 9f023ae..0000000 --- a/tests/Drivers/OutputDriverTest.php +++ /dev/null @@ -1,99 +0,0 @@ -format('Y-m-d H:i:s'); - $this->expectOutputString("[{$date}] OutputDriverTest.EMERGENCY: test"); - $loggr = new Loggr(new OutputDriver()); - $loggr->emergency('test'); - } - - /** - * @throws \Exception - */ - public function testAlert(): void - { - $date = (new DateTime)->format('Y-m-d H:i:s'); - $this->expectOutputString("[{$date}] OutputDriverTest.ALERT: test"); - $loggr = new Loggr(new OutputDriver()); - $loggr->alert('test'); - } - - /** - * @throws \Exception - */ - public function testCritical(): void - { - $date = (new DateTime)->format('Y-m-d H:i:s'); - $this->expectOutputString("[{$date}] OutputDriverTest.CRITICAL: test"); - $loggr = new Loggr(new OutputDriver()); - $loggr->critical('test'); - } - - /** - * @throws \Exception - */ - public function testError(): void - { - $date = (new DateTime)->format('Y-m-d H:i:s'); - $this->expectOutputString("[{$date}] OutputDriverTest.ERROR: test"); - $loggr = new Loggr(new OutputDriver()); - $loggr->error('test'); - } - - /** - * @throws \Exception - */ - public function testWarning(): void - { - $date = (new DateTime)->format('Y-m-d H:i:s'); - $this->expectOutputString("[{$date}] OutputDriverTest.WARNING: test"); - $loggr = new Loggr(new OutputDriver()); - $loggr->warning('test'); - } - - /** - * @throws \Exception - */ - public function testNotice(): void - { - $date = (new DateTime)->format('Y-m-d H:i:s'); - $this->expectOutputString("[{$date}] OutputDriverTest.NOTICE: test"); - $loggr = new Loggr(new OutputDriver()); - $loggr->notice('test'); - } - - /** - * @throws \Exception - */ - public function testInfo(): void - { - $date = (new DateTime)->format('Y-m-d H:i:s'); - $this->expectOutputString("[{$date}] OutputDriverTest.INFO: test"); - $loggr = new Loggr(new OutputDriver()); - $loggr->info('test'); - } - - /** - * @throws \Exception - */ - public function testDebug(): void - { - $date = (new DateTime)->format('Y-m-d H:i:s'); - $this->expectOutputString("[{$date}] OutputDriverTest.DEBUG: test"); - $loggr = new Loggr(new OutputDriver()); - $loggr->debug('test'); - } -} \ No newline at end of file diff --git a/tests/FileSystemDriverTest.php b/tests/FileSystemDriverTest.php new file mode 100644 index 0000000..5e4f8c3 --- /dev/null +++ b/tests/FileSystemDriverTest.php @@ -0,0 +1,152 @@ +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 diff --git a/tests/LoggrTest.php b/tests/LoggrTest.php index 4abae86..94a166c 100644 --- a/tests/LoggrTest.php +++ b/tests/LoggrTest.php @@ -1,7 +1,5 @@ format('Y-m-d H:i:s'); + $this->expectOutputString("[{$date}] OutputDriverTest.EMERGENCY: test"); + $loggr = new Loggr(new OutputDriver()); + $loggr->emergency('test'); + } + + /** + * @throws \Exception + */ + public function testAlert(): void + { + $date = (new DateTime)->format('Y-m-d H:i:s'); + $this->expectOutputString("[{$date}] OutputDriverTest.ALERT: test"); + $loggr = new Loggr(new OutputDriver()); + $loggr->alert('test'); + } + + /** + * @throws \Exception + */ + public function testCritical(): void + { + $date = (new DateTime)->format('Y-m-d H:i:s'); + $this->expectOutputString("[{$date}] OutputDriverTest.CRITICAL: test"); + $loggr = new Loggr(new OutputDriver()); + $loggr->critical('test'); + } + + /** + * @throws \Exception + */ + public function testError(): void + { + $date = (new DateTime)->format('Y-m-d H:i:s'); + $this->expectOutputString("[{$date}] OutputDriverTest.ERROR: test"); + $loggr = new Loggr(new OutputDriver()); + $loggr->error('test'); + } + + /** + * @throws \Exception + */ + public function testWarning(): void + { + $date = (new DateTime)->format('Y-m-d H:i:s'); + $this->expectOutputString("[{$date}] OutputDriverTest.WARNING: test"); + $loggr = new Loggr(new OutputDriver()); + $loggr->warning('test'); + } + + /** + * @throws \Exception + */ + public function testNotice(): void + { + $date = (new DateTime)->format('Y-m-d H:i:s'); + $this->expectOutputString("[{$date}] OutputDriverTest.NOTICE: test"); + $loggr = new Loggr(new OutputDriver()); + $loggr->notice('test'); + } + + /** + * @throws \Exception + */ + public function testInfo(): void + { + $date = (new DateTime)->format('Y-m-d H:i:s'); + $this->expectOutputString("[{$date}] OutputDriverTest.INFO: test"); + $loggr = new Loggr(new OutputDriver()); + $loggr->info('test'); + } + + /** + * @throws \Exception + */ + public function testDebug(): void + { + $date = (new DateTime)->format('Y-m-d H:i:s'); + $this->expectOutputString("[{$date}] OutputDriverTest.DEBUG: test"); + $loggr = new Loggr(new OutputDriver()); + $loggr->debug('test'); + } +} \ No newline at end of file -- cgit v1.2.3