1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
namespace Graze\Monolog\Handler; |
4
|
|
|
|
5
|
|
|
use Mockery as m; |
6
|
|
|
use Monolog\TestCase; |
7
|
|
|
|
8
|
|
|
class WhoopsHandlerTest extends TestCase |
9
|
|
|
{ |
10
|
|
|
public function setUp() |
11
|
|
|
{ |
12
|
|
|
if (!interface_exists('Whoops\Handler\HandlerInterface', true)) { |
13
|
|
|
$this->markTestSkipped('filp/whoops not installed'); |
14
|
|
|
} |
15
|
|
|
|
16
|
|
|
$this->handlerWhoops = m::mock('Whoops\Handler\HandlerInterface'); |
|
|
|
|
17
|
|
|
} |
18
|
|
|
|
19
|
|
|
public function testConstruct() |
20
|
|
|
{ |
21
|
|
|
$this->assertInstanceOf('Graze\\Monolog\\Handler\\WhoopsHandler', new WhoopsHandler($this->handlerWhoops)); |
22
|
|
|
} |
23
|
|
|
|
24
|
|
|
public function testInterface() |
25
|
|
|
{ |
26
|
|
|
$this->assertInstanceOf('Monolog\\Handler\\HandlerInterface', new WhoopsHandler($this->handlerWhoops)); |
27
|
|
|
} |
28
|
|
|
|
29
|
|
|
public function testHandleError() |
30
|
|
|
{ |
31
|
|
|
$record = $this->getRecord(300, 'test', ['file' => 'bar', 'line' => 1]); |
32
|
|
|
$handlerMonolog = new WhoopsHandler($this->handlerWhoops); |
33
|
|
|
|
34
|
|
|
$this->handlerWhoops |
35
|
|
|
->shouldReceive('setInspector') |
36
|
|
|
->once() |
37
|
|
|
->with(m::type('Whoops\Exception\Inspector')); |
38
|
|
|
|
39
|
|
|
$this->handlerWhoops |
40
|
|
|
->shouldReceive('setRun') |
41
|
|
|
->once() |
42
|
|
|
->with(m::type('Whoops\Run')); |
43
|
|
|
|
44
|
|
|
$this->handlerWhoops |
45
|
|
|
->shouldReceive('setException') |
46
|
|
|
->once() |
47
|
|
|
->with(m::type('Whoops\Exception\ErrorException')); |
48
|
|
|
|
49
|
|
|
$this->handlerWhoops |
50
|
|
|
->shouldReceive('handle') |
51
|
|
|
->once(); |
52
|
|
|
|
53
|
|
|
$handlerMonolog->handle($record); |
54
|
|
|
} |
55
|
|
|
|
56
|
|
|
public function testHandleException() |
57
|
|
|
{ |
58
|
|
|
$exception = new \Whoops\Exception\ErrorException('foo'); |
59
|
|
|
$record = $this->getRecord(300, 'foo', ['exception' => $exception]); |
60
|
|
|
$handlerMonolog = new WhoopsHandler($this->handlerWhoops); |
61
|
|
|
|
62
|
|
|
$this->handlerWhoops |
63
|
|
|
->shouldReceive('setInspector') |
64
|
|
|
->once() |
65
|
|
|
->with(m::type('Whoops\Exception\Inspector')); |
66
|
|
|
|
67
|
|
|
$this->handlerWhoops |
68
|
|
|
->shouldReceive('setRun') |
69
|
|
|
->once() |
70
|
|
|
->with(m::type('Whoops\Run')); |
71
|
|
|
|
72
|
|
|
$this->handlerWhoops |
73
|
|
|
->shouldReceive('setException') |
74
|
|
|
->once() |
75
|
|
|
->with($exception); |
76
|
|
|
|
77
|
|
|
$this->handlerWhoops |
78
|
|
|
->shouldReceive('handle') |
79
|
|
|
->once(); |
80
|
|
|
|
81
|
|
|
$handlerMonolog->handle($record); |
82
|
|
|
} |
83
|
|
|
|
84
|
|
|
/** |
85
|
|
|
* @requires PHP 7 |
86
|
|
|
*/ |
87
|
|
|
public function testHandleThrowable() |
88
|
|
|
{ |
89
|
|
|
$exception = new \TypeError('foo'); |
90
|
|
|
$record = $this->getRecord(300, 'foo', ['exception' => $exception]); |
91
|
|
|
$handlerMonolog = new WhoopsHandler($this->handlerWhoops); |
92
|
|
|
|
93
|
|
|
$this->handlerWhoops |
94
|
|
|
->shouldReceive('setInspector') |
95
|
|
|
->once() |
96
|
|
|
->with(m::type('Whoops\Exception\Inspector')); |
97
|
|
|
|
98
|
|
|
$this->handlerWhoops |
99
|
|
|
->shouldReceive('setRun') |
100
|
|
|
->once() |
101
|
|
|
->with(m::type('Whoops\Run')); |
102
|
|
|
|
103
|
|
|
$this->handlerWhoops |
104
|
|
|
->shouldReceive('setException') |
105
|
|
|
->once() |
106
|
|
|
->with($exception); |
107
|
|
|
|
108
|
|
|
$this->handlerWhoops |
109
|
|
|
->shouldReceive('handle') |
110
|
|
|
->once(); |
111
|
|
|
|
112
|
|
|
$handlerMonolog->handle($record); |
113
|
|
|
} |
114
|
|
|
|
115
|
|
|
/** |
116
|
|
|
* @dataProvider nonTriggeringData |
117
|
|
|
* |
118
|
|
|
* @param array $context |
119
|
|
|
*/ |
120
|
|
|
public function testContextWithNotEnoughInformationDoesNotTrigger(array $context) |
121
|
|
|
{ |
122
|
|
|
$record = $this->getRecord(300, 'test', $context); |
123
|
|
|
$handlerMonolog = new WhoopsHandler($this->handlerWhoops); |
124
|
|
|
$handlerMonolog->handle($record); |
125
|
|
|
} |
126
|
|
|
|
127
|
|
|
/** |
128
|
|
|
* @return array |
129
|
|
|
*/ |
130
|
|
|
public function nonTriggeringData() |
131
|
|
|
{ |
132
|
|
|
return [ |
133
|
|
|
[['file' => 'file']], |
134
|
|
|
[['line' => 1]], |
135
|
|
|
[[]], |
136
|
|
|
[['other' => 5]], |
137
|
|
|
]; |
138
|
|
|
} |
139
|
|
|
} |
140
|
|
|
|