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

lingFirst()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 6
Code Lines 4

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 1
eloc 4
nc 1
nop 0
dl 0
loc 6
rs 9.4285
c 0
b 0
f 0
1
<?php
2
namespace Graze\Monolog\Handler;
3
4
use Mockery as m;
5
use Monolog\Logger;
6
use Monolog\TestCase;
7
8
class RaygunHandlerTest extends TestCase
9
{
10
    public function setUp()
11
    {
12
        if (!class_exists('Raygun4php\RaygunClient')) {
13
            $this->markTestSkipped('mindscape/raygun4php not installed');
14
        }
15
16
        $this->client = m::mock('Raygun4php\RaygunClient');
0 ignored issues
show
Bug Best Practice introduced by
The property client does not exist. Although not strictly required by PHP, it is generally a best practice to declare properties explicitly.
Loading history...
17
    }
18
19
    public function testConstruct()
20
    {
21
        $this->assertInstanceOf('Graze\\Monolog\\Handler\\RaygunHandler', new RaygunHandler($this->client));
22
    }
23
24
    public function testInterface()
25
    {
26
        $this->assertInstanceOf('Monolog\\Handler\\HandlerInterface', new RaygunHandler($this->client));
27
    }
28
29
    public function testGetFormatter()
30
    {
31
        $handler = new RaygunHandler($this->client, 'foo');
0 ignored issues
show
Bug introduced by
'foo' of type string is incompatible with the type integer expected by parameter $level 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

31
        $handler = new RaygunHandler($this->client, /** @scrutinizer ignore-type */ 'foo');
Loading history...
32
        $this->assertInstanceOf('Monolog\\Formatter\\NormalizerFormatter', $handler->getFormatter());
33
    }
34
35
    public function testHandleError()
36
    {
37
        $record = $this->getRecord(300,
38
            'foo', array(
0 ignored issues
show
Coding Style introduced by
Short array syntax must be used to define arrays
Loading history...
39
                'file' => 'bar',
40
                'line' => 1,
41
            )
42
        );
43
        $record['context']['tags'] = array('foo');
0 ignored issues
show
Coding Style introduced by
Short array syntax must be used to define arrays
Loading history...
44
        $record['context']['timestamp'] = 1234567890;
45
        $record['extra'] = array('bar' => 'baz', 'tags' => array('bar'));
0 ignored issues
show
Coding Style introduced by
Short array syntax must be used to define arrays
Loading history...
46
        $formatted = array_merge($record,
47
            array(
0 ignored issues
show
Coding Style introduced by
Short array syntax must be used to define arrays
Loading history...
48
                'tags' => array('foo', 'bar'),
0 ignored issues
show
Coding Style introduced by
Short array syntax must be used to define arrays
Loading history...
49
                'timestamp' => 1234567890,
50
                'custom_data' => array('bar' => 'baz')
0 ignored issues
show
Coding Style introduced by
Short array syntax must be used to define arrays
Loading history...
51
            )
52
        );
53
54
        $formatter = m::mock('Monolog\\Formatter\\FormatterInterface');
55
        $handler = new RaygunHandler($this->client);
56
        $handler->setFormatter($formatter);
0 ignored issues
show
Bug introduced by
$formatter of type Mockery\MockInterface is incompatible with the type Monolog\Formatter\FormatterInterface expected by parameter $formatter of Monolog\Handler\AbstractHandler::setFormatter(). ( Ignorable by Annotation )

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

56
        $handler->setFormatter(/** @scrutinizer ignore-type */ $formatter);
Loading history...
57
58
        $formatter
59
             ->shouldReceive('format')
0 ignored issues
show
Unused Code introduced by
The call to Mockery\MockInterface::shouldReceive() has too many arguments starting with 'format'. ( Ignorable by Annotation )

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

59
             ->/** @scrutinizer ignore-call */ 
60
               shouldReceive('format')

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...
60
             ->once()
61
             ->with($record)
62
             ->andReturn($formatted);
63
        $this->client
64
             ->shouldReceive('SendError')
65
             ->once()
66
             ->with(0, 'foo', 'bar', 1, array('foo', 'bar'), array('bar' => 'baz'), 1234567890);
0 ignored issues
show
Coding Style introduced by
Short array syntax must be used to define arrays
Loading history...
67
68
        $handler->handle($record);
69
    }
70
71
    public function testHandleException()
72
    {
73
        $exception = new \Exception('foo');
74
        $record = $this->getRecord(300, 'foo', array('exception' => $exception));
0 ignored issues
show
Coding Style introduced by
Short array syntax must be used to define arrays
Loading history...
75
        $record['extra'] = array('bar' => 'baz', 'tags' => array('foo', 'bar'));
0 ignored issues
show
Coding Style introduced by
Short array syntax must be used to define arrays
Loading history...
76
        $record['extra']['timestamp'] = 1234567890;
77
        $formatted = array_merge($record,
78
            array(
0 ignored issues
show
Coding Style introduced by
Short array syntax must be used to define arrays
Loading history...
79
                'tags' => array('foo', 'bar'),
0 ignored issues
show
Coding Style introduced by
Short array syntax must be used to define arrays
Loading history...
80
                'timestamp' => 1234567890,
81
                'custom_data' => array('bar' => 'baz')
0 ignored issues
show
Coding Style introduced by
Short array syntax must be used to define arrays
Loading history...
82
            )
83
        );
84
        $formatted['context']['exception'] = array(
0 ignored issues
show
Coding Style introduced by
Short array syntax must be used to define arrays
Loading history...
85
            'class' => get_class($exception),
86
            'message' => $exception->getMessage(),
87
            'code' => $exception->getCode(),
88
            'file' => $exception->getFile().':'.$exception->getLine(),
89
        );
90
91
        $formatter = m::mock('Monolog\\Formatter\\FormatterInterface');
92
        $handler = new RaygunHandler($this->client);
93
        $handler->setFormatter($formatter);
0 ignored issues
show
Bug introduced by
$formatter of type Mockery\MockInterface is incompatible with the type Monolog\Formatter\FormatterInterface expected by parameter $formatter of Monolog\Handler\AbstractHandler::setFormatter(). ( Ignorable by Annotation )

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

93
        $handler->setFormatter(/** @scrutinizer ignore-type */ $formatter);
Loading history...
94
95
        $formatter
96
             ->shouldReceive('format')
0 ignored issues
show
Unused Code introduced by
The call to Mockery\MockInterface::shouldReceive() has too many arguments starting with 'format'. ( Ignorable by Annotation )

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

96
             ->/** @scrutinizer ignore-call */ 
97
               shouldReceive('format')

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...
97
             ->once()
98
             ->with($record)
99
             ->andReturn($formatted);
100
        $this->client
101
             ->shouldReceive('SendException')
102
             ->once()
103
             ->with($exception, array('foo', 'bar'), array('bar' => 'baz'), 1234567890);
0 ignored issues
show
Coding Style introduced by
Short array syntax must be used to define arrays
Loading history...
104
105
        $handler->handle($record);
106
    }
107
108
    public function testHandleEmptyDoesNothing()
109
    {
110
        $record = $this->getRecord(300, 'bar');
111
        $record['extra'] = array('bar' => 'baz', 'tags' => array('foo', 'bar'));
0 ignored issues
show
Coding Style introduced by
Short array syntax must be used to define arrays
Loading history...
112
        $record['extra']['timestamp'] = 1234567890;
113
        $formatted = array_merge($record,
114
            array(
0 ignored issues
show
Coding Style introduced by
Short array syntax must be used to define arrays
Loading history...
115
                'tags' => array('foo', 'bar'),
0 ignored issues
show
Coding Style introduced by
Short array syntax must be used to define arrays
Loading history...
116
                'timestamp' => 1234567890,
117
                'custom_data' => array('bar' => 'baz')
0 ignored issues
show
Coding Style introduced by
Short array syntax must be used to define arrays
Loading history...
118
            )
119
        );
120
121
        $formatter = m::mock('Monolog\\Formatter\\FormatterInterface');
122
        $handler = new RaygunHandler($this->client);
123
        $handler->setFormatter($formatter);
0 ignored issues
show
Bug introduced by
$formatter of type Mockery\MockInterface is incompatible with the type Monolog\Formatter\FormatterInterface expected by parameter $formatter of Monolog\Handler\AbstractHandler::setFormatter(). ( Ignorable by Annotation )

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

123
        $handler->setFormatter(/** @scrutinizer ignore-type */ $formatter);
Loading history...
124
125
        $formatter
126
            ->shouldReceive('format')
0 ignored issues
show
Unused Code introduced by
The call to Mockery\MockInterface::shouldReceive() has too many arguments starting with 'format'. ( Ignorable by Annotation )

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

126
            ->/** @scrutinizer ignore-call */ 
127
              shouldReceive('format')

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...
127
            ->once()
128
            ->with($record)
129
            ->andReturn($formatted);
130
131
        $handler->handle($record);
132
    }
133
134
    /**
135
     * @requires PHP 7
136
     */
137
    public function testHandleThrowable()
138
    {
139
        $exception = new \TypeError('foo');
140
        $record = $this->getRecord(300, 'foo', array('exception' => $exception));
0 ignored issues
show
Coding Style introduced by
Short array syntax must be used to define arrays
Loading history...
141
        $record['context']['tags'] = array('foo');
0 ignored issues
show
Coding Style introduced by
Short array syntax must be used to define arrays
Loading history...
142
        $formatted = array_merge($record,
143
            array(
0 ignored issues
show
Coding Style introduced by
Short array syntax must be used to define arrays
Loading history...
144
                'tags' => array('foo'),
0 ignored issues
show
Coding Style introduced by
Short array syntax must be used to define arrays
Loading history...
145
                'custom_data' => array(),
0 ignored issues
show
Coding Style introduced by
Short array syntax must be used to define arrays
Loading history...
146
                'timestamp' => null,
147
            )
148
        );
149
150
        $formatter = m::mock('Monolog\\Formatter\\FormatterInterface');
151
        $handler = new RaygunHandler($this->client);
152
        $handler->setFormatter($formatter);
0 ignored issues
show
Bug introduced by
$formatter of type Mockery\MockInterface is incompatible with the type Monolog\Formatter\FormatterInterface expected by parameter $formatter of Monolog\Handler\AbstractHandler::setFormatter(). ( Ignorable by Annotation )

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

152
        $handler->setFormatter(/** @scrutinizer ignore-type */ $formatter);
Loading history...
153
154
        $formatter
155
            ->shouldReceive('format')
0 ignored issues
show
Unused Code introduced by
The call to Mockery\MockInterface::shouldReceive() has too many arguments starting with 'format'. ( Ignorable by Annotation )

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

155
            ->/** @scrutinizer ignore-call */ 
156
              shouldReceive('format')

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...
156
            ->once()
157
            ->with($record)
158
            ->andReturn($formatted);
159
        $this->client
160
            ->shouldReceive('SendException')
161
            ->once()
162
            ->with($exception, array('foo'), array(), null);
0 ignored issues
show
Coding Style introduced by
Short array syntax must be used to define arrays
Loading history...
163
164
        $handler->handle($record);
165
    }
166
}
167