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