forked from ARCANEDEV/LogViewer
-
Notifications
You must be signed in to change notification settings - Fork 0
/
FactoryTest.php
285 lines (229 loc) · 8.08 KB
/
FactoryTest.php
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
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
<?php namespace Arcanedev\LogViewer\Tests\Utilities;
use Arcanedev\LogViewer\Tests\TestCase;
use Arcanedev\LogViewer\Utilities\Factory;
/**
* Class FactoryTest
*
* @package Arcanedev\LogViewer\Tests\Utilities
* @author ARCANEDEV <[email protected]>
*/
class FactoryTest extends TestCase
{
/* -----------------------------------------------------------------
| Properties
| -----------------------------------------------------------------
*/
/** @var \Arcanedev\LogViewer\Contracts\Utilities\Factory */
private $logFactory;
/* -----------------------------------------------------------------
| Main Methods
| -----------------------------------------------------------------
*/
protected function setUp(): void
{
parent::setUp();
$this->logFactory = $this->app->make(\Arcanedev\LogViewer\Contracts\Utilities\Factory::class);
}
protected function tearDown(): void
{
unset($this->logFactory);
parent::tearDown();
}
/* -----------------------------------------------------------------
| Tests
| -----------------------------------------------------------------
*/
/** @test */
public function it_can_be_instantiated()
{
static::assertInstanceOf(Factory::class, $this->logFactory);
}
/** @test */
public function it_can_get_filesystem_object()
{
$expectations = [
\Arcanedev\LogViewer\Contracts\Utilities\Filesystem::class,
\Arcanedev\LogViewer\Utilities\Filesystem::class,
];
foreach ($expectations as $expected) {
static::assertInstanceOf($expected, $this->logFactory->getFilesystem());
}
}
/** @test */
public function it_can_get_levels_object()
{
$expectations = [
\Arcanedev\LogViewer\Contracts\Utilities\LogLevels::class,
\Arcanedev\LogViewer\Utilities\LogLevels::class,
];
foreach ($expectations as $expected) {
static::assertInstanceOf($expected, $this->logFactory->getLevels());
}
}
/** @test */
public function it_can_get_log_entries()
{
$logEntries = $this->logFactory->entries($date = '2015-01-01');
foreach ($logEntries as $logEntry) {
static::assertLogEntry($date, $logEntry);
}
}
/** @test */
public function it_can_get_dates()
{
$dates = $this->logFactory->dates();
static::assertCount(2, $dates);
static::assertDates($dates);
}
/** @test */
public function it_can_get_all_logs()
{
$logs = $this->logFactory->all();
static::assertInstanceOf(\Arcanedev\LogViewer\Entities\LogCollection::class, $logs);
static::assertCount(2, $logs);
static::assertSame(2, $logs->count());
}
/** @test */
public function it_can_paginate_all_logs()
{
$logs = $this->logFactory->paginate();
static::assertInstanceOf(\Illuminate\Pagination\LengthAwarePaginator::class, $logs);
static::assertSame(30, $logs->perPage());
static::assertSame(2, $logs->total());
static::assertSame(1, $logs->lastPage());
static::assertSame(1, $logs->currentPage());
}
/** @test */
public function it_can_get_count()
{
static::assertSame(2, $this->logFactory->count());
}
/** @test */
public function it_can_can_set_custom_path()
{
$this->logFactory->setPath(storage_path('custom-path-logs'));
static::assertSame(1, $this->logFactory->count());
$logEntries = $this->logFactory->entries($date = '2015-01-03');
foreach ($logEntries as $logEntry) {
static::assertLogEntry($date, $logEntry);
}
}
/** @test */
public function it_can_get_total()
{
static::assertSame(16, $this->logFactory->total());
}
/** @test */
public function it_can_get_total_by_level()
{
foreach (self::$logLevels as $level) {
static::assertSame(2, $this->logFactory->total($level));
}
}
/** @test */
public function it_can_get_tree()
{
$tree = $this->logFactory->tree();
foreach ($tree as $date => $levels) {
static::assertDate($date);
// TODO: Complete the assertions
}
}
/** @test */
public function it_can_get_translated_tree()
{
$this->app->setLocale('fr');
$expected = [
'2015-01-02' => [
'all' => ['name' => 'Tous', 'count' => 8],
'emergency' => ['name' => 'Urgence', 'count' => 1],
'alert' => ['name' => 'Alerte', 'count' => 1],
'critical' => ['name' => 'Critique', 'count' => 1],
'error' => ['name' => 'Erreur', 'count' => 1],
'warning' => ['name' => 'Avertissement', 'count' => 1],
'notice' => ['name' => 'Notice', 'count' => 1],
'info' => ['name' => 'Info', 'count' => 1],
'debug' => ['name' => 'Debug', 'count' => 1],
],
'2015-01-01' => [
'all' => ['name' => 'Tous', 'count' => 8],
'emergency' => ['name' => 'Urgence', 'count' => 1],
'alert' => ['name' => 'Alerte', 'count' => 1],
'critical' => ['name' => 'Critique', 'count' => 1],
'error' => ['name' => 'Erreur', 'count' => 1],
'warning' => ['name' => 'Avertissement', 'count' => 1],
'notice' => ['name' => 'Notice', 'count' => 1],
'info' => ['name' => 'Info', 'count' => 1],
'debug' => ['name' => 'Debug', 'count' => 1],
]
];
static::assertSame($expected, $tree = $this->logFactory->tree(true));
}
/** @test */
public function it_can_get_menu()
{
$menu = $this->logFactory->menu();
foreach ($menu as $date => $item) {
static::assertDate($date);
// TODO: Complete the assertions
}
}
/** @test */
public function it_can_get_untranslated_menu()
{
$menu = $this->logFactory->menu(false);
foreach ($menu as $date => $item) {
static::assertDate($date);
// TODO: Complete the assertions
}
}
/** @test */
public function it_can_check_is_not_empty()
{
static::assertFalse($this->logFactory->isEmpty());
}
/** @test */
public function it_must_throw_a_filesystem_exception()
{
$this->expectException(\Arcanedev\LogViewer\Exceptions\LogNotFoundException::class);
$this->logFactory->get('2222-11-11'); // Future FTW
}
/** @test */
public function it_can_set_and_get_pattern()
{
$prefix = 'laravel-';
$date = '[0-9][0-9][0-9][0-9]-[0-9][0-9]-[0-9][0-9]';
$extension = '.log';
static::assertSame(
$prefix.$date.$extension,
$this->logFactory->getPattern()
);
$this->logFactory->setPattern($prefix, $date, $extension = '');
static::assertSame(
$prefix.$date.$extension,
$this->logFactory->getPattern()
);
$this->logFactory->setPattern($prefix = 'laravel-cli-', $date, $extension);
static::assertSame(
$prefix.$date.$extension,
$this->logFactory->getPattern()
);
$this->logFactory->setPattern($prefix, $date = '[0-9][0-9][0-9][0-9]', $extension);
static::assertSame(
$prefix.$date.$extension,
$this->logFactory->getPattern()
);
$this->logFactory->setPattern();
static::assertSame(
'laravel-[0-9][0-9][0-9][0-9]-[0-9][0-9]-[0-9][0-9].log',
$this->logFactory->getPattern()
);
$this->logFactory->setPattern(
'laravel-', '[0-9][0-9][0-9][0-9]-[0-9][0-9]-[0-9][0-9]', '.log'
);
static::assertSame(
'laravel-[0-9][0-9][0-9][0-9]-[0-9][0-9]-[0-9][0-9].log',
$this->logFactory->getPattern()
);
}
}