summaryrefslogtreecommitdiff
path: root/tests
diff options
context:
space:
mode:
authorAsko Nõmm <asko@nth.ee>2024-11-15 17:22:24 +0200
committerAsko Nõmm <asko@nth.ee>2024-11-15 17:22:24 +0200
commit086d719dc61d2c531e0b9fa51678b8e2f34dafdb (patch)
treed7b7c2a097dea2b16213992f7a8ab01b2494dee9 /tests
parent88ee33c51b9696eb9c4b31afeae9487b21c0565f (diff)
Improve tests.
Diffstat (limited to 'tests')
-rw-r--r--tests/FileSystemDriverTest.php27
-rw-r--r--tests/FormatTest.php124
-rw-r--r--tests/LoggrTest.php6
-rw-r--r--tests/OutputDriverTest.php24
4 files changed, 123 insertions, 58 deletions
diff --git a/tests/FileSystemDriverTest.php b/tests/FileSystemDriverTest.php
index a50adcc..2c98091 100644
--- a/tests/FileSystemDriverTest.php
+++ b/tests/FileSystemDriverTest.php
@@ -10,9 +10,6 @@ use Mockery\Adapter\Phpunit\MockeryTestCase;
class FileSystemDriverTest extends MockeryTestCase
{
- /**
- * @throws \Exception
- */
public function testEmergency(): void
{
$data = '';
@@ -22,9 +19,6 @@ class FileSystemDriverTest extends MockeryTestCase
$this->assertStringContainsString("[{$full_date}] FileSystemDriverTest.EMERGENCY: test", $data);
}
- /**
- * @throws \Exception
- */
public function testAlert(): void
{
$data = '';
@@ -34,9 +28,6 @@ class FileSystemDriverTest extends MockeryTestCase
$this->assertStringContainsString("[{$full_date}] FileSystemDriverTest.ALERT: test", $data);
}
- /**
- * @throws \Exception
- */
public function testCritical(): void
{
$data = '';
@@ -46,9 +37,6 @@ class FileSystemDriverTest extends MockeryTestCase
$this->assertStringContainsString("[{$full_date}] FileSystemDriverTest.CRITICAL: test", $data);
}
- /**
- * @throws \Exception
- */
public function testError(): void
{
$data = '';
@@ -58,9 +46,6 @@ class FileSystemDriverTest extends MockeryTestCase
$this->assertStringContainsString("[{$full_date}] FileSystemDriverTest.ERROR: test", $data);
}
- /**
- * @throws \Exception
- */
public function testWarning(): void
{
$data = '';
@@ -70,9 +55,6 @@ class FileSystemDriverTest extends MockeryTestCase
$this->assertStringContainsString("[{$full_date}] FileSystemDriverTest.WARNING: test", $data);
}
- /**
- * @throws \Exception
- */
public function testNotice(): void
{
$data = '';
@@ -82,9 +64,6 @@ class FileSystemDriverTest extends MockeryTestCase
$this->assertStringContainsString("[{$full_date}] FileSystemDriverTest.NOTICE: test", $data);
}
- /**
- * @throws \Exception
- */
public function testInfo(): void
{
$data = '';
@@ -94,9 +73,6 @@ class FileSystemDriverTest extends MockeryTestCase
$this->assertStringContainsString("[{$full_date}] FileSystemDriverTest.INFO: test", $data);
}
- /**
- * @throws \Exception
- */
public function testDebug(): void
{
$data = '';
@@ -106,9 +82,6 @@ class FileSystemDriverTest extends MockeryTestCase
$this->assertStringContainsString("[{$full_date}] FileSystemDriverTest.DEBUG: test", $data);
}
- /**
- * @throws \Exception
- */
public function testMultipleEntries(): void
{
$data = '';
diff --git a/tests/FormatTest.php b/tests/FormatTest.php
index 16f765d..06f30a3 100644
--- a/tests/FormatTest.php
+++ b/tests/FormatTest.php
@@ -27,6 +27,22 @@ class FormatTest extends MockeryTestCase
$this->assertEquals($expectedJson, $serializedMessage);
}
+ public function testJsonStr(): void
+ {
+ $message = new Message(
+ level: Level::Info,
+ trace: debug_backtrace()[0],
+ context: "test",
+ );
+
+ $format = Format::JSON;
+ $serializedMessage = $format->serialize($message);
+ $full_date = (new DateTime())->format('Y-m-d H:i:s');
+ $expectedJson = '{"date":"' . $full_date . '","level":"INFO","message":"","context":"test","trace":{"file":"TestCase","line":1182}}';
+
+ $this->assertEquals($expectedJson, $serializedMessage);
+ }
+
public function testIntelliJ(): void
{
$message = new Message(
@@ -60,6 +76,40 @@ class FormatTest extends MockeryTestCase
$this->assertEquals($expected, $serializedMessage);
}
+ public function testIntelliJContextStr(): void
+ {
+ $message = new Message(
+ level: Level::Info,
+ trace: debug_backtrace()[0],
+ content: "hello world",
+ context: "hello world",
+ );
+
+ $format = Format::IntelliJ;
+ $serializedMessage = $format->serialize($message);
+ $full_date = (new DateTime())->format('Y-m-d H:i:s');
+ $expected = "{$full_date} [1182] INFO - TestCase - hello world - hello world";
+
+ $this->assertEquals($expected, $serializedMessage);
+ }
+
+ public function testIntelliJContextNumeric(): void
+ {
+ $message = new Message(
+ level: Level::Info,
+ trace: debug_backtrace()[0],
+ content: "hello world",
+ context: 123456789,
+ );
+
+ $format = Format::IntelliJ;
+ $serializedMessage = $format->serialize($message);
+ $full_date = (new DateTime())->format('Y-m-d H:i:s');
+ $expected = "{$full_date} [1182] INFO - TestCase - hello world - 123456789";
+
+ $this->assertEquals($expected, $serializedMessage);
+ }
+
public function testLaravel(): void
{
$message = new Message(
@@ -93,6 +143,40 @@ class FormatTest extends MockeryTestCase
$this->assertEquals($expected, $serializedMessage);
}
+ public function testLaravelContextStr(): void
+ {
+ $message = new Message(
+ level: Level::Info,
+ trace: debug_backtrace()[0],
+ content: "hello world",
+ context: "hello world",
+ );
+
+ $format = Format::Laravel;
+ $serializedMessage = $format->serialize($message);
+ $full_date = (new DateTime())->format('Y-m-d H:i:s');
+ $expected = "[{$full_date}] TestCase.INFO: hello world - hello world";
+
+ $this->assertEquals($expected, $serializedMessage);
+ }
+
+ public function testLaravelContextNumeric(): void
+ {
+ $message = new Message(
+ level: Level::Info,
+ trace: debug_backtrace()[0],
+ content: "hello world",
+ context: 123456789,
+ );
+
+ $format = Format::Laravel;
+ $serializedMessage = $format->serialize($message);
+ $full_date = (new DateTime())->format('Y-m-d H:i:s');
+ $expected = "[{$full_date}] TestCase.INFO: hello world - 123456789";
+
+ $this->assertEquals($expected, $serializedMessage);
+ }
+
public function testSymfony(): void
{
$mock_datetime = Mockery::mock('DateTime');
@@ -120,13 +204,51 @@ class FormatTest extends MockeryTestCase
$message = new Message(
level: Level::Info,
trace: debug_backtrace()[0],
+ content: "hello world",
context: "hello world",
);
$format = Format::Symfony;
$serializedMessage = $format->serialize($message, $mock_datetime);
$full_date = $mock_datetime->format('Y-m-d\TH:i:s.uP');
- $expected = "[$full_date] TestCase.INFO: hello world";
+ $expected = "[$full_date] TestCase.INFO: hello world - hello world";
+
+ $this->assertEquals($expected, $serializedMessage);
+ }
+
+ public function testSymfonyNoContentOrContext(): void
+ {
+ $mock_datetime = Mockery::mock('DateTime');
+ $mock_datetime->shouldReceive('format')->andReturn('2020-01-01T00:00:00.000000P');
+
+ $message = new Message(
+ level: Level::Info,
+ trace: debug_backtrace()[0],
+ context: [],
+ );
+
+ $format = Format::Symfony;
+ $serializedMessage = $format->serialize($message, $mock_datetime);
+ $full_date = $mock_datetime->format('Y-m-d\TH:i:s.uP');
+ $expected = "[$full_date] TestCase.INFO: ";
+
+ $this->assertEquals($expected, $serializedMessage);
+ }
+
+ public function testSymfonyNoContext(): void
+ {
+ $mock_datetime = Mockery::mock('DateTime');
+ $mock_datetime->shouldReceive('format')->andReturn('2020-01-01T00:00:00.000000P');
+
+ $message = new Message(
+ level: Level::Info,
+ trace: debug_backtrace()[0],
+ );
+
+ $format = Format::Symfony;
+ $serializedMessage = $format->serialize($message, $mock_datetime);
+ $full_date = $mock_datetime->format('Y-m-d\TH:i:s.uP');
+ $expected = "[$full_date] TestCase.INFO: ";
$this->assertEquals($expected, $serializedMessage);
}
diff --git a/tests/LoggrTest.php b/tests/LoggrTest.php
index eb2f5ab..a7c3628 100644
--- a/tests/LoggrTest.php
+++ b/tests/LoggrTest.php
@@ -8,9 +8,6 @@ use PHPUnit\Framework\TestCase;
class LoggrTest extends TestCase
{
- /**
- * @throws \Exception
- */
public function testNoDriver(): void
{
$loggr = new Loggr();
@@ -18,9 +15,6 @@ class LoggrTest extends TestCase
$this->assertEquals("Driver or format not set.", $loggr->error);
}
- /**
- * @throws \Exception
- */
public function testNoFormat(): void
{
$loggr = new Loggr(new OutputDriver());
diff --git a/tests/OutputDriverTest.php b/tests/OutputDriverTest.php
index e235cd9..3fa5ae2 100644
--- a/tests/OutputDriverTest.php
+++ b/tests/OutputDriverTest.php
@@ -9,9 +9,6 @@ use PHPUnit\Framework\TestCase;
class OutputDriverTest extends TestCase
{
- /**
- * @throws \Exception
- */
public function testEmergency(): void
{
$date = (new DateTime)->format('Y-m-d H:i:s');
@@ -20,9 +17,6 @@ class OutputDriverTest extends TestCase
$loggr->emergency('test');
}
- /**
- * @throws \Exception
- */
public function testAlert(): void
{
$date = (new DateTime)->format('Y-m-d H:i:s');
@@ -31,9 +25,6 @@ class OutputDriverTest extends TestCase
$loggr->alert('test');
}
- /**
- * @throws \Exception
- */
public function testCritical(): void
{
$date = (new DateTime)->format('Y-m-d H:i:s');
@@ -42,9 +33,6 @@ class OutputDriverTest extends TestCase
$loggr->critical('test');
}
- /**
- * @throws \Exception
- */
public function testError(): void
{
$date = (new DateTime)->format('Y-m-d H:i:s');
@@ -53,9 +41,6 @@ class OutputDriverTest extends TestCase
$loggr->error('test');
}
- /**
- * @throws \Exception
- */
public function testWarning(): void
{
$date = (new DateTime)->format('Y-m-d H:i:s');
@@ -64,9 +49,6 @@ class OutputDriverTest extends TestCase
$loggr->warning('test');
}
- /**
- * @throws \Exception
- */
public function testNotice(): void
{
$date = (new DateTime)->format('Y-m-d H:i:s');
@@ -75,9 +57,6 @@ class OutputDriverTest extends TestCase
$loggr->notice('test');
}
- /**
- * @throws \Exception
- */
public function testInfo(): void
{
$date = (new DateTime)->format('Y-m-d H:i:s');
@@ -86,9 +65,6 @@ class OutputDriverTest extends TestCase
$loggr->info('test');
}
- /**
- * @throws \Exception
- */
public function testDebug(): void
{
$date = (new DateTime)->format('Y-m-d H:i:s');