1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
declare(strict_types=1); |
4
|
|
|
|
5
|
|
|
namespace Tests; |
6
|
|
|
|
7
|
|
|
use PHPUnit\Framework\TestCase; |
8
|
|
|
use VPA\Logger\ConsoleLogger; |
9
|
|
|
|
10
|
|
|
class ConsoleLoggerTest extends TestCase |
11
|
|
|
{ |
12
|
|
|
private ConsoleLogger $logger; |
13
|
|
|
|
14
|
|
|
public function setUp(): void |
15
|
|
|
{ |
16
|
|
|
parent::setUp(); |
17
|
|
|
$this->logger = new ConsoleLogger(); |
18
|
|
|
} |
19
|
|
|
|
20
|
|
|
public function testInitClass() |
21
|
|
|
{ |
22
|
|
|
$this->assertTrue($this->logger instanceof ConsoleLogger); |
23
|
|
|
} |
24
|
|
|
|
25
|
|
|
public function testEmergency() |
26
|
|
|
{ |
27
|
|
|
ob_start(); |
28
|
|
|
$this->logger->emergency("testEmergency {Interpolation}", ['Interpolation' => 'InterpolationEmergency']); |
29
|
|
|
$capture = ob_get_clean(); |
30
|
|
|
$this->assertTrue(str_contains($capture, "0;35") !== false); |
31
|
|
|
$this->assertTrue(str_contains($capture, "testEmergency") !== false); |
32
|
|
|
$this->assertTrue(str_contains($capture, "InterpolationEmergency") !== false); |
33
|
|
|
} |
34
|
|
|
|
35
|
|
|
public function testAlert() |
36
|
|
|
{ |
37
|
|
|
ob_start(); |
38
|
|
|
$this->logger->alert("testAlert {Interpolation}", ['Interpolation' => 'InterpolationAlert']); |
39
|
|
|
$capture = ob_get_clean(); |
40
|
|
|
$this->assertTrue(str_contains($capture, "1;31") !== false); |
41
|
|
|
$this->assertTrue(str_contains($capture, "testAlert") !== false); |
42
|
|
|
$this->assertTrue(str_contains($capture, "InterpolationAlert") !== false); |
43
|
|
|
} |
44
|
|
|
|
45
|
|
|
public function testCritical() |
46
|
|
|
{ |
47
|
|
|
ob_start(); |
48
|
|
|
$this->logger->critical("testCritical {Interpolation}", ['Interpolation' => 'InterpolationCritical']); |
49
|
|
|
$capture = ob_get_clean(); |
50
|
|
|
$this->assertTrue(str_contains($capture, "0;31") !== false); |
51
|
|
|
$this->assertTrue(str_contains($capture, "testCritical") !== false); |
52
|
|
|
$this->assertTrue(str_contains($capture, "InterpolationCritical") !== false); |
53
|
|
|
} |
54
|
|
|
|
55
|
|
|
public function testError() |
56
|
|
|
{ |
57
|
|
|
ob_start(); |
58
|
|
|
$this->logger->error("testError {Interpolation}", ['Interpolation' => 'InterpolationError']); |
59
|
|
|
$capture = ob_get_clean(); |
60
|
|
|
$this->assertTrue(str_contains($capture, "0;31") !== false); |
61
|
|
|
$this->assertTrue(str_contains($capture, "testError") !== false); |
62
|
|
|
$this->assertTrue(str_contains($capture, "InterpolationError") !== false); |
63
|
|
|
} |
64
|
|
|
|
65
|
|
|
public function testWarning() |
66
|
|
|
{ |
67
|
|
|
ob_start(); |
68
|
|
|
$this->logger->warning("testWarning {Interpolation}", ['Interpolation' => 'InterpolationWarning']); |
69
|
|
|
$capture = ob_get_clean(); |
70
|
|
|
$this->assertTrue(str_contains($capture, "1;37") !== false); |
71
|
|
|
$this->assertTrue(str_contains($capture, "testWarning") !== false); |
72
|
|
|
$this->assertTrue(str_contains($capture, "InterpolationWarning") !== false); |
73
|
|
|
} |
74
|
|
|
|
75
|
|
|
public function testNotice() |
76
|
|
|
{ |
77
|
|
|
ob_start(); |
78
|
|
|
$this->logger->notice("testNotice {Interpolation}", ['Interpolation' => 'InterpolationNotice']); |
79
|
|
|
$capture = ob_get_clean(); |
80
|
|
|
$this->assertTrue(str_contains($capture, "1;33")); |
81
|
|
|
$this->assertTrue(str_contains($capture, "testNotice")); |
82
|
|
|
$this->assertTrue(str_contains($capture, "InterpolationNotice")); |
83
|
|
|
} |
84
|
|
|
|
85
|
|
|
public function testInfo() |
86
|
|
|
{ |
87
|
|
|
ob_start(); |
88
|
|
|
$this->logger->info("testInfo {Interpolation}", ['Interpolation' => 'InterpolationInfo']); |
89
|
|
|
$capture = ob_get_clean(); |
90
|
|
|
$this->assertTrue(str_contains($capture, "0;32") !== false); |
91
|
|
|
$this->assertTrue(str_contains($capture, "testInfo") !== false); |
92
|
|
|
$this->assertTrue(str_contains($capture, "InterpolationInfo") !== false); |
93
|
|
|
} |
94
|
|
|
|
95
|
|
|
public function testDebug() |
96
|
|
|
{ |
97
|
|
|
ob_start(); |
98
|
|
|
$this->logger->debug("testDebug {Interpolation}", ['Interpolation' => 'InterpolationDebug']); |
99
|
|
|
$capture = ob_get_clean(); |
100
|
|
|
$this->assertTrue(str_contains($capture, "1;34") !== false); |
101
|
|
|
$this->assertTrue(str_contains($capture, "testDebug") !== false); |
102
|
|
|
$this->assertTrue(str_contains($capture, "InterpolationDebug") !== false); |
103
|
|
|
} |
104
|
|
|
|
105
|
|
|
public function testTable() |
106
|
|
|
{ |
107
|
|
|
ob_start(); |
108
|
|
|
$this->logger->debug("test1DArray {tableData}", [ |
109
|
|
|
'tableData' => [ |
110
|
|
|
'key' => 'value', |
111
|
|
|
] |
112
|
|
|
]); |
113
|
|
|
$capture = ob_get_clean(); |
114
|
|
|
$this->assertTrue(str_contains($capture, "test1DArray") !== false); |
115
|
|
|
$this->assertTrue(str_contains($capture, "key | value") !== false); |
116
|
|
|
} |
117
|
|
|
} |
118
|
|
|
|