From f82340f781a1ef8c48e8696aee0e345b5731436b Mon Sep 17 00:00:00 2001 From: Asko Nõmm Date: Sun, 10 Nov 2024 23:02:27 +0200 Subject: Add phpunit.xml --- .github/workflows/coverage.yml | 6 ++++-- tests/FileSystemDriverTest.php | 40 ++++++++++++++++++++-------------------- 2 files changed, 24 insertions(+), 22 deletions(-) diff --git a/.github/workflows/coverage.yml b/.github/workflows/coverage.yml index daf2733..3be18db 100644 --- a/.github/workflows/coverage.yml +++ b/.github/workflows/coverage.yml @@ -18,8 +18,10 @@ jobs: - name: Set-up Composer uses: php-actions/composer@v6 - - name: Give all permissions to tests/ directory - run: chmod -R 0777 tests/ + - name: Set up logs dir + run: | + mkdir logs/ + chmod -R 0777 logs/ - name: Run tests and collect coverage run: ./vendor/bin/phpunit tests --coverage-clover coverage.xml tests diff --git a/tests/FileSystemDriverTest.php b/tests/FileSystemDriverTest.php index f642b4f..3384c64 100644 --- a/tests/FileSystemDriverTest.php +++ b/tests/FileSystemDriverTest.php @@ -15,9 +15,9 @@ class FileSystemDriverTest extends TestCase public function testEmergency(): void { $date = new DateTime(); - $loggr = new Loggr(new FileSystemDriver(__DIR__ . '/logs')); + $loggr = new Loggr(new FileSystemDriver(__DIR__ . '/../logs')); $loggr->emergency('test'); - $lines = file(__DIR__ . '/logs/' . $date->format('Y-m-d') . '.log'); + $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); @@ -29,9 +29,9 @@ class FileSystemDriverTest extends TestCase public function testAlert(): void { $date = new DateTime(); - $loggr = new Loggr(new FileSystemDriver(__DIR__ . '/logs')); + $loggr = new Loggr(new FileSystemDriver(__DIR__ . '/../logs')); $loggr->alert('test'); - $lines = file(__DIR__ . '/logs/' . $date->format('Y-m-d') . '.log'); + $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); @@ -43,9 +43,9 @@ class FileSystemDriverTest extends TestCase public function testCritical(): void { $date = new DateTime(); - $loggr = new Loggr(new FileSystemDriver(__DIR__ . '/logs')); + $loggr = new Loggr(new FileSystemDriver(__DIR__ . '/../logs')); $loggr->critical('test'); - $lines = file(__DIR__ . '/logs/' . $date->format('Y-m-d') . '.log'); + $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); @@ -57,9 +57,9 @@ class FileSystemDriverTest extends TestCase public function testError(): void { $date = new DateTime(); - $loggr = new Loggr(new FileSystemDriver(__DIR__ . '/logs')); + $loggr = new Loggr(new FileSystemDriver(__DIR__ . '/../logs')); $loggr->error('test'); - $lines = file(__DIR__ . '/logs/' . $date->format('Y-m-d') . '.log'); + $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); @@ -71,9 +71,9 @@ class FileSystemDriverTest extends TestCase public function testWarning(): void { $date = new DateTime(); - $loggr = new Loggr(new FileSystemDriver(__DIR__ . '/logs')); + $loggr = new Loggr(new FileSystemDriver(__DIR__ . '/../logs')); $loggr->warning('test'); - $lines = file(__DIR__ . '/logs/' . $date->format('Y-m-d') . '.log'); + $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); @@ -85,9 +85,9 @@ class FileSystemDriverTest extends TestCase public function testNotice(): void { $date = new DateTime(); - $loggr = new Loggr(new FileSystemDriver(__DIR__ . '/logs')); + $loggr = new Loggr(new FileSystemDriver(__DIR__ . '/../logs')); $loggr->notice('test'); - $lines = file(__DIR__ . '/logs/' . $date->format('Y-m-d') . '.log'); + $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); @@ -99,9 +99,9 @@ class FileSystemDriverTest extends TestCase public function testInfo(): void { $date = new DateTime(); - $loggr = new Loggr(new FileSystemDriver(__DIR__ . '/logs')); + $loggr = new Loggr(new FileSystemDriver(__DIR__ . '/../logs')); $loggr->info('test'); - $lines = file(__DIR__ . '/logs/' . $date->format('Y-m-d') . '.log'); + $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); @@ -113,9 +113,9 @@ class FileSystemDriverTest extends TestCase public function testDebug(): void { $date = new DateTime(); - $loggr = new Loggr(new FileSystemDriver(__DIR__ . '/logs')); + $loggr = new Loggr(new FileSystemDriver(__DIR__ . '/../logs')); $loggr->debug('test'); - $lines = file(__DIR__ . '/logs/' . $date->format('Y-m-d') . '.log'); + $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); @@ -127,7 +127,7 @@ class FileSystemDriverTest extends TestCase public function testMultipleEntries(): void { $date = new DateTime(); - $loggr = new Loggr(new FileSystemDriver(__DIR__ . '/logs')); + $loggr = new Loggr(new FileSystemDriver(__DIR__ . '/../logs')); $loggr->emergency('test'); $loggr->alert('test'); $loggr->critical('test'); @@ -137,7 +137,7 @@ class FileSystemDriverTest extends TestCase $loggr->info('test'); $loggr->debug('test'); - $lines = file(__DIR__ . '/logs/' . $date->format('Y-m-d') . '.log'); + $lines = file(__DIR__ . '/../logs/' . $date->format('Y-m-d') . '.log'); $this->assertCount(8, $lines); $first_line = $lines[0]; @@ -149,7 +149,7 @@ class FileSystemDriverTest extends TestCase public function tearDown(): void { - array_map('unlink', glob(__DIR__ . '/logs/*')); - rmdir(__DIR__ . '/logs'); + array_map('unlink', glob(__DIR__ . '/../logs/*')); + rmdir(__DIR__ . '/../logs'); } } \ No newline at end of file -- cgit v1.2.3