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
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
|
<?php
namespace Asko\Loggr\Tests\Drivers;
use Asko\Loggr\Drivers\FileSystemDriver;
use Asko\Loggr\Loggr;
use DateTime;
use PHPUnit\Framework\TestCase;
class FileSystemDriverTest extends TestCase
{
/**
* @throws \Exception
*/
public function testEmergency(): void
{
$date = new DateTime();
$loggr = new Loggr(new FileSystemDriver(__DIR__ . '/logs'));
$loggr->emergency('test');
$lines = file(__DIR__ . '/logs/' . $date->format('Y-m-d') . '.log');
$last_line = end($lines);
$full_date = $date->format('Y-m-d H:i:s');
$this->assertStringContainsString("[{$full_date}] FileSystemDriverTest.EMERGENCY: test", $last_line);
}
/**
* @throws \Exception
*/
public function testAlert(): void
{
$date = new DateTime();
$loggr = new Loggr(new FileSystemDriver(__DIR__ . '/logs'));
$loggr->alert('test');
$lines = file(__DIR__ . '/logs/' . $date->format('Y-m-d') . '.log');
$last_line = end($lines);
$full_date = $date->format('Y-m-d H:i:s');
$this->assertStringContainsString("[{$full_date}] FileSystemDriverTest.ALERT: test", $last_line);
}
/**
* @throws \Exception
*/
public function testCritical(): void
{
$date = new DateTime();
$loggr = new Loggr(new FileSystemDriver(__DIR__ . '/logs'));
$loggr->critical('test');
$lines = file(__DIR__ . '/logs/' . $date->format('Y-m-d') . '.log');
$last_line = end($lines);
$full_date = $date->format('Y-m-d H:i:s');
$this->assertStringContainsString("[{$full_date}] FileSystemDriverTest.CRITICAL: test", $last_line);
}
/**
* @throws \Exception
*/
public function testError(): void
{
$date = new DateTime();
$loggr = new Loggr(new FileSystemDriver(__DIR__ . '/logs'));
$loggr->error('test');
$lines = file(__DIR__ . '/logs/' . $date->format('Y-m-d') . '.log');
$last_line = end($lines);
$full_date = $date->format('Y-m-d H:i:s');
$this->assertStringContainsString("[{$full_date}] FileSystemDriverTest.ERROR: test", $last_line);
}
/**
* @throws \Exception
*/
public function testWarning(): void
{
$date = new DateTime();
$loggr = new Loggr(new FileSystemDriver(__DIR__ . '/logs'));
$loggr->warning('test');
$lines = file(__DIR__ . '/logs/' . $date->format('Y-m-d') . '.log');
$last_line = end($lines);
$full_date = $date->format('Y-m-d H:i:s');
$this->assertStringContainsString("[{$full_date}] FileSystemDriverTest.WARNING: test", $last_line);
}
/**
* @throws \Exception
*/
public function testNotice(): void
{
$date = new DateTime();
$loggr = new Loggr(new FileSystemDriver(__DIR__ . '/logs'));
$loggr->notice('test');
$lines = file(__DIR__ . '/logs/' . $date->format('Y-m-d') . '.log');
$last_line = end($lines);
$full_date = $date->format('Y-m-d H:i:s');
$this->assertStringContainsString("[{$full_date}] FileSystemDriverTest.NOTICE: test", $last_line);
}
/**
* @throws \Exception
*/
public function testInfo(): void
{
$date = new DateTime();
$loggr = new Loggr(new FileSystemDriver(__DIR__ . '/logs'));
$loggr->info('test');
$lines = file(__DIR__ . '/logs/' . $date->format('Y-m-d') . '.log');
$last_line = end($lines);
$full_date = $date->format('Y-m-d H:i:s');
$this->assertStringContainsString("[{$full_date}] FileSystemDriverTest.INFO: test", $last_line);
}
/**
* @throws \Exception
*/
public function testDebug(): void
{
$date = new DateTime();
$loggr = new Loggr(new FileSystemDriver(__DIR__ . '/logs'));
$loggr->debug('test');
$lines = file(__DIR__ . '/logs/' . $date->format('Y-m-d') . '.log');
$last_line = end($lines);
$full_date = $date->format('Y-m-d H:i:s');
$this->assertStringContainsString("[{$full_date}] FileSystemDriverTest.DEBUG: test", $last_line);
}
/**
* @throws \Exception
*/
public function testMultipleEntries(): void
{
$date = new DateTime();
$loggr = new Loggr(new FileSystemDriver(__DIR__ . '/logs'));
$loggr->emergency('test');
$loggr->alert('test');
$loggr->critical('test');
$loggr->error('test');
$loggr->warning('test');
$loggr->notice('test');
$loggr->info('test');
$loggr->debug('test');
$lines = file(__DIR__ . '/logs/' . $date->format('Y-m-d') . '.log');
$this->assertCount(8, $lines);
$first_line = $lines[0];
$last_line = end($lines);
$full_date = $date->format('Y-m-d H:i:s');
$this->assertStringContainsString("[{$full_date}] FileSystemDriverTest.EMERGENCY: test", $first_line);
$this->assertStringContainsString("[{$full_date}] FileSystemDriverTest.DEBUG: test", $last_line);
}
public function tearDown(): void
{
array_map('unlink', glob(__DIR__ . '/logs/*'));
rmdir(__DIR__ . '/logs');
}
}
|