diff options
| author | Asko Nõmm <asko@nth.ee> | 2024-11-10 22:49:52 +0200 |
|---|---|---|
| committer | Asko Nõmm <asko@nth.ee> | 2024-11-10 22:49:52 +0200 |
| commit | 246e5a24a5ceedf364e06bb13e0a26cf46ee9507 (patch) | |
| tree | c8ee52d337a040a5c3ce83ec5b1e72fca984cf6e /tests/FileSystemDriverTest.php | |
| parent | 882741f201426fa1ae39b461b7ba5bd8db6a77dc (diff) | |
Add phpunit.xml
Diffstat (limited to 'tests/FileSystemDriverTest.php')
| -rw-r--r-- | tests/FileSystemDriverTest.php | 152 |
1 files changed, 152 insertions, 0 deletions
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 @@ +<?php + +use Asko\Loggr\Drivers\FileSystemDriver; +use Asko\Loggr\Loggr; +use PHPUnit\Framework\TestCase; + +class FileSystemDriverTest extends TestCase +{ + /** + * @throws \Exception + */ + public function testEmergency(): void + { + $date = new DateTime(); + $loggr = new Loggr(new FileSystemDriver(__DIR__ . '/logs')); + $loggr->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 |
