RaygunFormatterTest::testFormatException()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 41
Code Lines 33

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 1
eloc 33
nc 1
nop 0
dl 0
loc 41
rs 9.392
c 0
b 0
f 0
1
<?php
2
3
namespace Graze\Monolog\Formatter;
4
5
use Monolog\TestCase;
6
7
class RaygunFormatterTest extends TestCase
8
{
9
10
    public function testFormat()
11
    {
12
        $input = [
13
            'level_name' => 'WARNING',
14
            'channel' => 'test',
15
            'message' => 'foo',
16
            'datetime' => new \DateTime,
17
            'extra' => ['baz' => 'qux', 'tags' => ['bar']],
18
            'context' => [
19
                'file' => 'bar',
20
                'line' => 1,
21
                'bar' => 'baz',
22
                'timestamp' => 1234567890,
23
                'tags' => ['foo'],
24
            ],
25
        ];
26
        $expected = [
27
            'level_name' => 'WARNING',
28
            'channel' => 'test',
29
            'message' => 'foo',
30
            'datetime' => date('Y-m-d'),
31
            'context' => [
32
                'file' => 'bar',
33
                'line' => 1,
34
            ],
35
            'extra' => [],
36
            'tags' => ['bar', 'foo'],
37
            'timestamp' => 1234567890,
38
            'custom_data' => ['bar' => 'baz', 'baz' => 'qux'],
39
        ];
40
41
        $formatter = new RaygunFormatter('Y-m-d');
42
        $this->assertEquals($expected, $formatter->format($input));
43
    }
44
45
    public function testFormatException()
46
    {
47
        $formatter = new RaygunFormatter('Y-m-d');
48
        $ex = new \Exception('foo');
49
        $someClass = new \stdClass();
50
        $someClass->foo = 'bar';
51
        $input = [
52
            'level_name' => 'WARNING',
53
            'channel' => 'test',
54
            'message' => 'foo',
55
            'datetime' => new \DateTime,
56
            'extra' => [
57
                'bar' => 'baz',
58
                'tags' => ['foo', 'bar'],
59
                'timestamp' => 1234567890,
60
                'someClass' => $someClass
61
            ],
62
            'context' =>  [
63
                'exception' => $ex,
64
            ],
65
        ];
66
        $formatted = $formatter->format($input);
67
        unset($formatted['context']['exception']['trace'], $formatted['context']['exception']['previous'], $formatted['context']['exception']['code']);
68
69
        $this->assertEquals([
70
                'level_name' => 'WARNING',
71
                'channel' => 'test',
72
                'message' => 'foo',
73
                'datetime' => date('Y-m-d'),
74
                'context' =>  [
75
                    'exception' => [
76
                        'class' => get_class($ex),
77
                        'message' => $ex->getMessage(),
78
                        'file' => $ex->getFile().':'.$ex->getLine(),
79
                    ]
80
                ],
81
                'extra' => [],
82
                'tags' => ['foo', 'bar'],
83
                'timestamp' => 1234567890,
84
                'custom_data' => ['bar' => 'baz', 'someClass' => '[object] (stdClass: {"foo":"bar"})'],
85
            ], $formatted);
86
    }
87
}
88