-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathLogWriterTest.php
More file actions
executable file
·102 lines (79 loc) · 2.77 KB
/
LogWriterTest.php
File metadata and controls
executable file
·102 lines (79 loc) · 2.77 KB
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
<?php
use Illuminate\Events\Dispatcher;
use Illuminate\Log\Writer;
use L4\Tests\BackwardCompatibleTestCase;
use Mockery as m;
use Monolog\Handler\ErrorLogHandler;
use Monolog\Handler\RotatingFileHandler;
use Monolog\Handler\StreamHandler;
use Monolog\Logger;
class LogWriterTest extends BackwardCompatibleTestCase
{
protected function tearDown(): void
{
m::close();
}
public function testFileHandlerCanBeAdded()
{
$writer = new Writer($monolog = m::mock(Logger::class));
$monolog->shouldReceive('pushHandler')->once()->with(m::type(StreamHandler::class));
$writer->useFiles(__DIR__);
}
public function testRotatingFileHandlerCanBeAdded()
{
$writer = new Writer($monolog = m::mock(Logger::class));
$monolog->shouldReceive('pushHandler')->once()->with(m::type(RotatingFileHandler::class));
$writer->useDailyFiles(__DIR__, 5);
}
public function testErrorLogHandlerCanBeAdded()
{
$writer = new Writer($monolog = m::mock(Logger::class));
$monolog->shouldReceive('pushHandler')->once()->with(m::type(ErrorLogHandler::class));
$writer->useErrorLog();
}
public function testMagicMethodsPassErrorAdditionsToMonolog()
{
$writer = new Writer($monolog = m::mock(Logger::class));
$monolog->shouldReceive('error')->once()->with('foo');
$writer->error('foo');
}
public function testWriterFiresEventsDispatcher()
{
$writer = new Writer($monolog = m::mock(Logger::class), $events = new Illuminate\Events\Dispatcher);
$monolog->shouldReceive('error')->once()->with('foo');
$events->listen('illuminate.log', function($level, $message, array $context = [])
{
$_SERVER['__log.level'] = $level;
$_SERVER['__log.message'] = $message;
$_SERVER['__log.context'] = $context;
});
$writer->error('foo');
$this->assertTrue(isset($_SERVER['__log.level']));
$this->assertEquals('error', $_SERVER['__log.level']);
unset($_SERVER['__log.level']);
$this->assertTrue(isset($_SERVER['__log.message']));
$this->assertEquals('foo', $_SERVER['__log.message']);
unset($_SERVER['__log.message']);
$this->assertTrue(isset($_SERVER['__log.context']));
$this->assertEquals([], $_SERVER['__log.context']);
unset($_SERVER['__log.context']);
}
public function testListenShortcutFailsWithNoDispatcher()
{
$this->expectException(RuntimeException::class);
$writer = new Writer($monolog = m::mock(Logger::class));
$writer->listen(
function () {
}
);
}
public function testListenShortcut()
{
$writer = new Writer($monolog = m::mock(Logger::class), $events = m::mock(
Dispatcher::class
));
$callback = function() { return 'success'; };
$events->shouldReceive('listen')->with('illuminate.log', $callback)->once();
$writer->listen($callback);
}
}