JSConsoleLoggerTest   A
last analyzed

Complexity

Total Complexity 11

Size/Duplication

Total Lines 110
Duplicated Lines 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
eloc 64
c 1
b 0
f 0
dl 0
loc 110
rs 10
wmc 11

11 Methods

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