Completed
Push — master ( 1d6c1f...26ec6b )
by Harry
06:29
created

testErrorWithExceptionTriggersLogger()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 10
Code Lines 6

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 1
eloc 6
nc 1
nop 0
dl 0
loc 10
rs 9.4285
c 0
b 0
f 0
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);
0 ignored issues
show
Bug introduced by
$this->raygun of type Mockery\MockInterface is incompatible with the type Raygun4php\RaygunClient expected by parameter $client of Graze\Monolog\Handler\RaygunHandler::__construct(). ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-type  annotation

23
        $this->handler = new RaygunHandler(/** @scrutinizer ignore-type */ $this->raygun, Logger::NOTICE);
Loading history...
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