1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
|
<?php
namespace Asko\Loggr\Tests;
use Asko\Loggr\Format;
use Asko\Loggr\Level;
use Asko\Loggr\Message;
use DateTime;
use Mockery;
use Mockery\Adapter\Phpunit\MockeryTestCase;
class FormatTest extends MockeryTestCase
{
public function testJson(): void
{
$message = new Message(
level: Level::Info,
trace: debug_backtrace()[0],
context: ['message' => '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","context":{"message":"test"},"trace":{"file":"TestCase","line":1182}}';
$this->assertEquals($expectedJson, $serializedMessage);
}
public function testIntelliJ(): void
{
$message = new Message(
level: Level::Info,
trace: debug_backtrace()[0],
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 - {\"message\":\"test\"}";
$this->assertEquals($expected, $serializedMessage);
}
public function testIntelliJStr(): void
{
$message = new Message(
level: Level::Info,
trace: debug_backtrace()[0],
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";
$this->assertEquals($expected, $serializedMessage);
}
public function testLaravel(): void
{
$message = new Message(
level: Level::Info,
trace: debug_backtrace()[0],
context: ['message' => 'test'],
);
$format = Format::Laravel;
$serializedMessage = $format->serialize($message);
$full_date = (new DateTime())->format('Y-m-d H:i:s');
$expected = "[{$full_date}] TestCase.INFO: {\"message\":\"test\"}";
$this->assertEquals($expected, $serializedMessage);
}
public function testLaravelStr(): void
{
$message = new Message(
level: Level::Info,
trace: debug_backtrace()[0],
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";
$this->assertEquals($expected, $serializedMessage);
}
public function testSymfony(): 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: ['message' => 'test'],
);
$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: {\"message\":\"test\"}";
$this->assertEquals($expected, $serializedMessage);
}
public function testSymfonyStr(): 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: "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";
$this->assertEquals($expected, $serializedMessage);
}
}
|