diff options
| author | Asko Nõmm <asko@nmm.ee> | 2025-04-10 11:39:12 +0300 |
|---|---|---|
| committer | Asko Nõmm <asko@nmm.ee> | 2025-04-10 11:39:12 +0300 |
| commit | 233bbd9d9262002fbeee96114c08d90a7b45edef (patch) | |
| tree | 221c950939479e45b7bb58c81584a3e0fa5fa414 /tests | |
| parent | 38289fea342485943c55bbeaaacd117be7742cc7 (diff) | |
Fix tests
Diffstat (limited to 'tests')
| -rw-r--r-- | tests/FormatTest.php | 115 | ||||
| -rw-r--r-- | tests/LoggrTest.php | 67 |
2 files changed, 96 insertions, 86 deletions
diff --git a/tests/FormatTest.php b/tests/FormatTest.php index 4222a81..cc2923a 100644 --- a/tests/FormatTest.php +++ b/tests/FormatTest.php @@ -16,44 +16,42 @@ class FormatTest extends MockeryTestCase $message = new Message( level: Level::Info, trace: debug_backtrace()[0], - context: ['test' => 'test'], + context: ["test" => "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":"test"},"trace":{"file":"TestCase","line":1182}}'; + $full_date = (new DateTime())->format("Y-m-d H:i:s"); + $expectedJson = + '{"date":"' . + $full_date . + '","level":"INFO","message":"","context":{"test":"test"},"trace":{"file":"TestCase","line":1104}}'; $this->assertEquals($expectedJson, $serializedMessage); } public function testJsonStr(): void { - $message = new Message( - level: Level::Info, - trace: debug_backtrace()[0], - context: "test", - ); + $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}}'; + $full_date = (new DateTime())->format("Y-m-d H:i:s"); + $expectedJson = + '{"date":"' . + $full_date . + '","level":"INFO","message":"","context":"test","trace":{"file":"TestCase","line":1104}}'; $this->assertEquals($expectedJson, $serializedMessage); } public function testJsonFails(): void { - $message = new Message( - level: Level::Info, - trace: debug_backtrace()[0], - context: NAN, - ); + $message = new Message(level: Level::Info, trace: debug_backtrace()[0], context: NAN); $format = Format::JSON; $serializedMessage = $format->serialize($message); - $expectedJson = ''; + $expectedJson = ""; $this->assertEquals($expectedJson, $serializedMessage); } @@ -63,14 +61,14 @@ class FormatTest extends MockeryTestCase $message = new Message( level: Level::Info, trace: debug_backtrace()[0], - content: 'test', - context: ['message' => 'test'], + content: "test", + context: ["message" => "test"] ); $format = Format::IntelliJ; $serializedMessage = $format->serialize($message); - $full_date = (new DateTime())->format('Y-m-d H:i:s'); - $expected = "$full_date [1182] INFO - TestCase - test {\"message\":\"test\"}"; + $full_date = (new DateTime())->format("Y-m-d H:i:s"); + $expected = "$full_date [1104] INFO - TestCase - test {\"message\":\"test\"}"; $this->assertEquals($expected, $serializedMessage); } @@ -80,13 +78,13 @@ class FormatTest extends MockeryTestCase $message = new Message( level: Level::Info, trace: debug_backtrace()[0], - content: "hello world", + content: "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"; + $full_date = (new DateTime())->format("Y-m-d H:i:s"); + $expected = "$full_date [1104] INFO - TestCase - hello world"; $this->assertEquals($expected, $serializedMessage); } @@ -97,13 +95,13 @@ class FormatTest extends MockeryTestCase level: Level::Info, trace: debug_backtrace()[0], content: "hello world", - context: "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\""; + $full_date = (new DateTime())->format("Y-m-d H:i:s"); + $expected = "$full_date [1104] INFO - TestCase - hello world \"hello world\""; $this->assertEquals($expected, $serializedMessage); } @@ -114,13 +112,13 @@ class FormatTest extends MockeryTestCase level: Level::Info, trace: debug_backtrace()[0], content: "hello world", - context: 123456789, + 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"; + $full_date = (new DateTime())->format("Y-m-d H:i:s"); + $expected = "$full_date [1104] INFO - TestCase - hello world 123456789"; $this->assertEquals($expected, $serializedMessage); } @@ -130,13 +128,13 @@ class FormatTest extends MockeryTestCase $message = new Message( level: Level::Info, trace: debug_backtrace()[0], - content: 'test', - context: ['message' => 'test'], + content: "test", + context: ["message" => "test"] ); $format = Format::Laravel; $serializedMessage = $format->serialize($message); - $full_date = (new DateTime())->format('Y-m-d H:i:s'); + $full_date = (new DateTime())->format("Y-m-d H:i:s"); $expected = "[$full_date] TestCase.INFO: test {\"message\":\"test\"}"; $this->assertEquals($expected, $serializedMessage); @@ -147,12 +145,12 @@ class FormatTest extends MockeryTestCase $message = new Message( level: Level::Info, trace: debug_backtrace()[0], - content: "hello world", + content: "hello world" ); $format = Format::Laravel; $serializedMessage = $format->serialize($message); - $full_date = (new DateTime())->format('Y-m-d H:i:s'); + $full_date = (new DateTime())->format("Y-m-d H:i:s"); $expected = "[$full_date] TestCase.INFO: hello world"; $this->assertEquals($expected, $serializedMessage); @@ -164,12 +162,12 @@ class FormatTest extends MockeryTestCase level: Level::Info, trace: debug_backtrace()[0], content: "hello world", - context: "hello world", + context: "hello world" ); $format = Format::Laravel; $serializedMessage = $format->serialize($message); - $full_date = (new DateTime())->format('Y-m-d H:i:s'); + $full_date = (new DateTime())->format("Y-m-d H:i:s"); $expected = "[$full_date] TestCase.INFO: hello world \"hello world\""; $this->assertEquals($expected, $serializedMessage); @@ -181,12 +179,12 @@ class FormatTest extends MockeryTestCase level: Level::Info, trace: debug_backtrace()[0], content: "hello world", - context: 123456789, + context: 123456789 ); $format = Format::Laravel; $serializedMessage = $format->serialize($message); - $full_date = (new DateTime())->format('Y-m-d H:i:s'); + $full_date = (new DateTime())->format("Y-m-d H:i:s"); $expected = "[$full_date] TestCase.INFO: hello world 123456789"; $this->assertEquals($expected, $serializedMessage); @@ -194,18 +192,18 @@ class FormatTest extends MockeryTestCase public function testSymfony(): void { - $mock_datetime = Mockery::mock('DateTime'); - $mock_datetime->shouldReceive('format')->andReturn('2020-01-01T00:00:00.000000P'); + $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: ['message' => 'test'], + context: ["message" => "test"] ); $format = Format::Symfony; $serializedMessage = $format->serialize($message, $mock_datetime); - $full_date = $mock_datetime->format('Y-m-d\TH:i:s.uP'); + $full_date = $mock_datetime->format("Y-m-d\TH:i:s.uP"); $expected = "[$full_date] TestCase.INFO: {\"message\":\"test\"}"; $this->assertEquals($expected, $serializedMessage); @@ -213,19 +211,19 @@ class FormatTest extends MockeryTestCase public function testSymfonyStr(): void { - $mock_datetime = Mockery::mock('DateTime'); - $mock_datetime->shouldReceive('format')->andReturn('2020-01-01T00:00:00.000000P'); + $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], content: "hello world", - context: "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'); + $full_date = $mock_datetime->format("Y-m-d\TH:i:s.uP"); $expected = "[$full_date] TestCase.INFO: hello world \"hello world\""; $this->assertEquals($expected, $serializedMessage); @@ -233,18 +231,14 @@ class FormatTest extends MockeryTestCase public function testSymfonyNoContentOrContext(): void { - $mock_datetime = Mockery::mock('DateTime'); - $mock_datetime->shouldReceive('format')->andReturn('2020-01-01T00:00:00.000000P'); + $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: [], - ); + $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'); + $full_date = $mock_datetime->format("Y-m-d\TH:i:s.uP"); $expected = "[$full_date] TestCase.INFO: []"; $this->assertEquals($expected, $serializedMessage); @@ -252,19 +246,16 @@ class FormatTest extends MockeryTestCase public function testSymfonyNoContext(): void { - $mock_datetime = Mockery::mock('DateTime'); - $mock_datetime->shouldReceive('format')->andReturn('2020-01-01T00:00:00.000000P'); + $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], - ); + $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'); + $full_date = $mock_datetime->format("Y-m-d\TH:i:s.uP"); $expected = "[$full_date] TestCase.INFO:"; $this->assertEquals($expected, $serializedMessage); } -}
\ No newline at end of file +} diff --git a/tests/LoggrTest.php b/tests/LoggrTest.php index 29cdce2..2503609 100644 --- a/tests/LoggrTest.php +++ b/tests/LoggrTest.php @@ -12,7 +12,7 @@ class LoggrTest extends TestCase public function testNoDriver(): void { $logger = new Loggr(); - $logger->info('test'); + $logger->info("test"); $this->assertEquals("Driver or format not set.", $logger->error); } @@ -20,63 +20,82 @@ class LoggrTest extends TestCase { $logger = new Loggr(new OutputDriver()); $logger->format = null; - $logger->info('test'); + $logger->info("test"); $this->assertEquals("Driver or format not set.", $logger->error); } public function testInterpolation(): void { - $full_date = (new DateTime())->format('Y-m-d H:i:s'); - $this->expectOutputString("[$full_date] LoggrTest.INFO: test something {\"interpolation\":\"something\"}"); + $full_date = (new DateTime())->format("Y-m-d H:i:s"); + $this->expectOutputString( + "[$full_date] LoggrTest.INFO: test something {\"interpolation\":\"something\"}" . + PHP_EOL + ); $logger = new Loggr(new OutputDriver()); - $logger->info('test {interpolation}', ['interpolation' => 'something']); + $logger->info("test {interpolation}", ["interpolation" => "something"]); } public function testNestedInterpolation(): void { - $full_date = (new DateTime())->format('Y-m-d H:i:s'); - $this->expectOutputString("[$full_date] LoggrTest.INFO: test something {\"nested\":{\"interpolation\":\"something\"}}"); + $full_date = (new DateTime())->format("Y-m-d H:i:s"); + $this->expectOutputString( + "[$full_date] LoggrTest.INFO: test something {\"nested\":{\"interpolation\":\"something\"}}" . + PHP_EOL + ); $logger = new Loggr(new OutputDriver()); - $logger->info('test {nested.interpolation}', ['nested' => ['interpolation' => 'something']]); + $logger->info("test {nested.interpolation}", [ + "nested" => ["interpolation" => "something"], + ]); } public function testIntegerInterpolation(): void { - $full_date = (new DateTime())->format('Y-m-d H:i:s'); - $this->expectOutputString("[$full_date] LoggrTest.INFO: test 1234567890 {\"integer\":1234567890}"); + $full_date = (new DateTime())->format("Y-m-d H:i:s"); + $this->expectOutputString( + "[$full_date] LoggrTest.INFO: test 1234567890 {\"integer\":1234567890}" . PHP_EOL + ); $logger = new Loggr(new OutputDriver()); - $logger->info('test {integer}', ['integer' => 1234567890]); + $logger->info("test {integer}", ["integer" => 1234567890]); } public function testBooleanInterpolation(): void { - $full_date = (new DateTime())->format('Y-m-d H:i:s'); - $this->expectOutputString("[$full_date] LoggrTest.INFO: test 1 {\"boolean\":true}"); + $full_date = (new DateTime())->format("Y-m-d H:i:s"); + $this->expectOutputString( + "[$full_date] LoggrTest.INFO: test 1 {\"boolean\":true}" . PHP_EOL + ); $logger = new Loggr(new OutputDriver()); - $logger->info('test {boolean}', ['boolean' => true]); + $logger->info("test {boolean}", ["boolean" => true]); } public function testDoubleInterpolation(): void { - $full_date = (new DateTime())->format('Y-m-d H:i:s'); - $this->expectOutputString("[$full_date] LoggrTest.INFO: test 1234567890.1235 {\"double\":1234567890.1234567}"); + $full_date = (new DateTime())->format("Y-m-d H:i:s"); + $this->expectOutputString( + "[$full_date] LoggrTest.INFO: test 1234567890.1235 {\"double\":1234567890.1234567}" . + PHP_EOL + ); $logger = new Loggr(new OutputDriver()); - $logger->info('test {double}', ['double' => 1234567890.1234567]); + $logger->info("test {double}", ["double" => 1234567890.1234567]); } public function testNullInterpolation(): void { - $full_date = (new DateTime())->format('Y-m-d H:i:s'); - $this->expectOutputString("[$full_date] LoggrTest.INFO: test null {\"null\":null}"); + $full_date = (new DateTime())->format("Y-m-d H:i:s"); + $this->expectOutputString( + "[$full_date] LoggrTest.INFO: test null {\"null\":null}" . PHP_EOL + ); $logger = new Loggr(new OutputDriver()); - $logger->info('test {null}', ['null' => null]); + $logger->info("test {null}", ["null" => null]); } public function testObjectInterpolation(): void { - $full_date = (new DateTime())->format('Y-m-d H:i:s'); - $this->expectOutputString("[$full_date] LoggrTest.INFO: test test {\"object\":{\"test\":\"test\"}}"); + $full_date = (new DateTime())->format("Y-m-d H:i:s"); + $this->expectOutputString( + "[$full_date] LoggrTest.INFO: test test {\"object\":{\"test\":\"test\"}}" . PHP_EOL + ); $logger = new Loggr(new OutputDriver()); - $logger->info('test {object.test}', ['object' => (object) ['test' => 'test']]); + $logger->info("test {object.test}", ["object" => (object) ["test" => "test"]]); } -}
\ No newline at end of file +} |
