1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
namespace Graze\Monolog\Handler; |
4
|
|
|
|
5
|
|
|
use Mockery; |
6
|
|
|
use Mockery\MockInterface; |
7
|
|
|
use Monolog\Logger; |
8
|
|
|
use PHPUnit\Framework\TestCase; |
9
|
|
|
use Raygun4php\RaygunClient; |
10
|
|
|
use RuntimeException; |
11
|
|
|
|
12
|
|
|
class RaygunHandlerIntegrationTest extends TestCase |
13
|
|
|
{ |
14
|
|
|
/** @var Logger */ |
15
|
|
|
private $logger; |
16
|
|
|
/** @var RaygunClient|MockInterface */ |
17
|
|
|
private $raygun; |
18
|
|
|
/** @var RaygunHandler */ |
19
|
|
|
private $handler; |
20
|
|
|
|
21
|
|
|
public function setUp() |
22
|
|
|
{ |
23
|
|
|
$this->raygun = Mockery::mock(RaygunClient::class); |
24
|
|
|
$this->handler = new RaygunHandler($this->raygun, Logger::NOTICE); |
|
|
|
|
25
|
|
|
$this->logger = new Logger('raygunHandlerTest', [$this->handler]); |
26
|
|
|
} |
27
|
|
|
|
28
|
|
|
public function testErrorWithExceptionTriggersLogger() |
29
|
|
|
{ |
30
|
|
|
$exception = new RuntimeException('test exception'); |
31
|
|
|
|
32
|
|
|
$this->raygun |
33
|
|
|
->shouldReceive('SendException') |
|
|
|
|
34
|
|
|
->once() |
35
|
|
|
->with($exception, [], [], null); |
36
|
|
|
|
37
|
|
|
$this->logger->error('test error', ['exception' => $exception]); |
38
|
|
|
} |
39
|
|
|
|
40
|
|
|
public function testErrorWithErrorWillTriggerLogger() |
41
|
|
|
{ |
42
|
|
|
$this->raygun |
43
|
|
|
->shouldReceive('SendError') |
|
|
|
|
44
|
|
|
->once() |
45
|
|
|
->with(0, "test line error", __FILE__, 5, [], [], null); |
46
|
|
|
$this->logger->error('test line error', ['file' => __FILE__, 'line' => 5]); |
47
|
|
|
} |
48
|
|
|
|
49
|
|
|
public function testErrorWithNoLineWillDoNothing() |
50
|
|
|
{ |
51
|
|
|
$this->logger->error('test line error', ['file' => __FILE__]); |
52
|
|
|
} |
53
|
|
|
|
54
|
|
|
public function testErrorWithNoFileWillDoNothing() |
55
|
|
|
{ |
56
|
|
|
$this->logger->error('test line error', ['line' => __FILE__]); |
57
|
|
|
} |
58
|
|
|
|
59
|
|
|
public function testErrorWithNeitherWillDoNothing() |
60
|
|
|
{ |
61
|
|
|
$this->logger->error('test line error'); |
62
|
|
|
} |
63
|
|
|
} |
64
|
|
|
|