Completed
Pull Request — master (#26)
by Harry
05:53
created

RaygunHandlerIntegrationTest::setUp()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 5
Code Lines 3

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 1
eloc 3
nc 1
nop 0
dl 0
loc 5
rs 9.4285
c 0
b 0
f 0
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);
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

24
        $this->handler = new RaygunHandler(/** @scrutinizer ignore-type */ $this->raygun, Logger::NOTICE);
Loading history...
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')
0 ignored issues
show
Unused Code introduced by
The call to Mockery\MockInterface::shouldReceive() has too many arguments starting with 'SendException'. ( Ignorable by Annotation )

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

33
            ->/** @scrutinizer ignore-call */ 
34
              shouldReceive('SendException')

This check compares calls to functions or methods with their respective definitions. If the call has more arguments than are defined, it raises an issue.

If a function is defined several times with a different number of parameters, the check may pick up the wrong definition and report false positives. One codebase where this has been known to happen is Wordpress. Please note the @ignore annotation hint above.

Loading history...
Bug introduced by
The method shouldReceive() does not exist on Raygun4php\RaygunClient. ( Ignorable by Annotation )

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

33
            ->/** @scrutinizer ignore-call */ 
34
              shouldReceive('SendException')

This check looks for calls to methods that do not seem to exist on a given type. It looks for the method on the type itself as well as in inherited classes or implemented interfaces.

This is most likely a typographical error or the method has been renamed.

Loading history...
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')
0 ignored issues
show
Unused Code introduced by
The call to Mockery\MockInterface::shouldReceive() has too many arguments starting with 'SendError'. ( Ignorable by Annotation )

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

43
            ->/** @scrutinizer ignore-call */ 
44
              shouldReceive('SendError')

This check compares calls to functions or methods with their respective definitions. If the call has more arguments than are defined, it raises an issue.

If a function is defined several times with a different number of parameters, the check may pick up the wrong definition and report false positives. One codebase where this has been known to happen is Wordpress. Please note the @ignore annotation hint above.

Loading history...
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