1
|
|
|
<?php |
2
|
|
|
namespace Graze\Monolog\Handler; |
3
|
|
|
|
4
|
|
|
use Mockery as m; |
5
|
|
|
use Monolog\TestCase; |
6
|
|
|
|
7
|
|
|
class WhoopsHandlerTest extends TestCase |
8
|
|
|
{ |
9
|
|
|
public function setUp() |
10
|
|
|
{ |
11
|
|
|
if (!interface_exists('Whoops\Handler\HandlerInterface', true)) { |
12
|
|
|
$this->markTestSkipped('filp/whoops not installed'); |
13
|
|
|
} |
14
|
|
|
|
15
|
|
|
$this->handlerWhoops = m::mock('Whoops\Handler\HandlerInterface'); |
|
|
|
|
16
|
|
|
} |
17
|
|
|
|
18
|
|
|
public function testConstruct() |
19
|
|
|
{ |
20
|
|
|
$this->assertInstanceOf('Graze\\Monolog\\Handler\\WhoopsHandler', new WhoopsHandler($this->handlerWhoops)); |
21
|
|
|
} |
22
|
|
|
|
23
|
|
|
public function testInterface() |
24
|
|
|
{ |
25
|
|
|
$this->assertInstanceOf('Monolog\\Handler\\HandlerInterface', new WhoopsHandler($this->handlerWhoops)); |
26
|
|
|
} |
27
|
|
|
|
28
|
|
|
public function testHandleError() |
29
|
|
|
{ |
30
|
|
|
$record = $this->getRecord(300, 'test', array('file' => 'bar', 'line' => 1)); |
|
|
|
|
31
|
|
|
|
32
|
|
|
$formatter = m::mock('Monolog\\Formatter\\FormatterInterface'); |
|
|
|
|
33
|
|
|
|
34
|
|
|
$handlerMonolog = new WhoopsHandler($this->handlerWhoops); |
35
|
|
|
|
36
|
|
|
$this->handlerWhoops |
37
|
|
|
->shouldReceive('setInspector') |
38
|
|
|
->once() |
39
|
|
|
->with(m::type('Whoops\Exception\Inspector')); |
40
|
|
|
|
41
|
|
|
$this->handlerWhoops |
42
|
|
|
->shouldReceive('setRun') |
43
|
|
|
->once() |
44
|
|
|
->with(m::type('Whoops\Run')); |
45
|
|
|
|
46
|
|
|
$this->handlerWhoops |
47
|
|
|
->shouldReceive('setException') |
48
|
|
|
->once() |
49
|
|
|
->with(m::type('Whoops\Exception\ErrorException')); |
50
|
|
|
|
51
|
|
|
$this->handlerWhoops |
52
|
|
|
->shouldReceive('handle') |
53
|
|
|
->once(); |
54
|
|
|
|
55
|
|
|
$handlerMonolog->handle($record); |
56
|
|
|
} |
57
|
|
|
|
58
|
|
|
public function testHandleException() |
59
|
|
|
{ |
60
|
|
|
$exception = new \Whoops\Exception\ErrorException('foo'); |
61
|
|
|
|
62
|
|
|
$record = $this->getRecord(300, 'foo', array('exception' => $exception)); |
|
|
|
|
63
|
|
|
|
64
|
|
|
$formatter = m::mock('Monolog\\Formatter\\FormatterInterface'); |
|
|
|
|
65
|
|
|
|
66
|
|
|
$handlerMonolog = new WhoopsHandler($this->handlerWhoops); |
67
|
|
|
|
68
|
|
|
$this->handlerWhoops |
69
|
|
|
->shouldReceive('setInspector') |
70
|
|
|
->once() |
71
|
|
|
->with(m::type('Whoops\Exception\Inspector')); |
72
|
|
|
|
73
|
|
|
$this->handlerWhoops |
74
|
|
|
->shouldReceive('setRun') |
75
|
|
|
->once() |
76
|
|
|
->with(m::type('Whoops\Run')); |
77
|
|
|
|
78
|
|
|
$this->handlerWhoops |
79
|
|
|
->shouldReceive('setException') |
80
|
|
|
->once() |
81
|
|
|
->with($exception); |
82
|
|
|
|
83
|
|
|
$this->handlerWhoops |
84
|
|
|
->shouldReceive('handle') |
85
|
|
|
->once(); |
86
|
|
|
|
87
|
|
|
$handlerMonolog->handle($record); |
88
|
|
|
} |
89
|
|
|
} |
90
|
|
|
|