|
1
|
|
|
<?php |
|
2
|
|
|
|
|
3
|
|
|
namespace Koded\Logging; |
|
4
|
|
|
|
|
5
|
|
|
use Exception; |
|
6
|
|
|
use Koded\Logging\Processors\Memory; |
|
7
|
|
|
use PHPUnit\Framework\TestCase; |
|
8
|
|
|
|
|
9
|
|
|
class LogTest extends TestCase |
|
10
|
|
|
{ |
|
11
|
|
|
/** |
|
12
|
|
|
* @var Log |
|
13
|
|
|
*/ |
|
14
|
|
|
private $SUT; |
|
15
|
|
|
|
|
16
|
|
|
public function test_default_setup() |
|
17
|
|
|
{ |
|
18
|
|
|
$this->assertAttributeSame(false, 'deferred', $this->SUT); |
|
19
|
|
|
$this->assertAttributeSame('d/m/Y H:i:s.u', 'dateFormat', $this->SUT); |
|
20
|
|
|
$this->assertAttributeSame('UTC', 'timezone', $this->SUT); |
|
21
|
|
|
$this->assertAttributeEmpty('processors', $this->SUT); |
|
22
|
|
|
$this->assertAttributeEmpty('messages', $this->SUT); |
|
23
|
|
|
} |
|
24
|
|
|
|
|
25
|
|
|
public function test_attach_and_detach() |
|
26
|
|
|
{ |
|
27
|
|
|
$processor = new Memory([]); |
|
28
|
|
|
$this->assertAttributeCount(0, 'processors', $this->SUT); |
|
29
|
|
|
|
|
30
|
|
|
$this->SUT->attach($processor); |
|
31
|
|
|
$this->assertAttributeCount(1, 'processors', $this->SUT); |
|
32
|
|
|
|
|
33
|
|
|
$this->SUT->detach($processor); |
|
34
|
|
|
$this->assertAttributeCount(0, 'processors', $this->SUT); |
|
35
|
|
|
} |
|
36
|
|
|
|
|
37
|
|
|
public function test_log_suppression() |
|
38
|
|
|
{ |
|
39
|
|
|
$processor = new Memory([ |
|
40
|
|
|
'levels' => 0 // suppress the logger completely |
|
41
|
|
|
]); |
|
42
|
|
|
|
|
43
|
|
|
$processor->update([ |
|
44
|
|
|
[ |
|
45
|
|
|
'level' => -1, // this is ignored |
|
46
|
|
|
'levelname' => 'DEBUG', |
|
47
|
|
|
'message' => 'Hello', |
|
48
|
|
|
'timestamp' => 1234567890 |
|
49
|
|
|
] |
|
50
|
|
|
]); |
|
51
|
|
|
|
|
52
|
|
|
$this->assertSame('', $processor->formatted()); |
|
53
|
|
|
} |
|
54
|
|
|
|
|
55
|
|
|
public function test_exception() |
|
56
|
|
|
{ |
|
57
|
|
|
$processor = new Memory([]); |
|
58
|
|
|
$this->SUT->exception(new Exception('The message', 1), $processor); |
|
59
|
|
|
|
|
60
|
|
|
$this->assertAttributeContains('[CRITICAL]', 'formatted', $processor); |
|
61
|
|
|
$this->assertAttributeContains('The message', 'formatted', $processor); |
|
62
|
|
|
} |
|
63
|
|
|
|
|
64
|
|
|
protected function setUp(): void |
|
65
|
|
|
{ |
|
66
|
|
|
$this->SUT = new Log([]); |
|
67
|
|
|
} |
|
68
|
|
|
} |
|
69
|
|
|
|