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