Passed
Push — master ( ddd97a...25aa58 )
by Harry
06:46
created

RaygunFormatterTest::testFormat()   B

Complexity

Conditions 1
Paths 1

Size

Total Lines 33
Code Lines 26

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 1
eloc 26
nc 1
nop 0
dl 0
loc 33
rs 8.8571
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 = array(
0 ignored issues
show
Coding Style introduced by
Short array syntax must be used to define arrays
Loading history...
13
            'level_name' => 'WARNING',
14
            'channel' => 'test',
15
            'message' => 'foo',
16
            'datetime' => new \DateTime,
17
            'extra' => array('baz' => 'qux', 'tags' => array('bar')),
0 ignored issues
show
Coding Style introduced by
Short array syntax must be used to define arrays
Loading history...
18
            'context' => array(
0 ignored issues
show
Coding Style introduced by
Short array syntax must be used to define arrays
Loading history...
19
                'file' => 'bar',
20
                'line' => 1,
21
                'bar' => 'baz',
22
                'timestamp' => 1234567890,
23
                'tags' => array('foo'),
0 ignored issues
show
Coding Style introduced by
Short array syntax must be used to define arrays
Loading history...
24
            ),
25
        );
26
        $expected = array(
0 ignored issues
show
Coding Style introduced by
Short array syntax must be used to define arrays
Loading history...
27
            'level_name' => 'WARNING',
28
            'channel' => 'test',
29
            'message' => 'foo',
30
            'datetime' => date('Y-m-d'),
31
            'context' => array(
0 ignored issues
show
Coding Style introduced by
Short array syntax must be used to define arrays
Loading history...
32
                'file' => 'bar',
33
                'line' => 1,
34
            ),
35
            'extra' => array(),
0 ignored issues
show
Coding Style introduced by
Short array syntax must be used to define arrays
Loading history...
36
            'tags' => array('bar', 'foo'),
0 ignored issues
show
Coding Style introduced by
Short array syntax must be used to define arrays
Loading history...
37
            'timestamp' => 1234567890,
38
            'custom_data' => array('bar' => 'baz', 'baz' => 'qux'),
0 ignored issues
show
Coding Style introduced by
Short array syntax must be used to define arrays
Loading history...
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 = array(
0 ignored issues
show
Coding Style introduced by
Short array syntax must be used to define arrays
Loading history...
52
            'level_name' => 'WARNING',
53
            'channel' => 'test',
54
            'message' => 'foo',
55
            'datetime' => new \DateTime,
56
            'extra' => array(
0 ignored issues
show
Coding Style introduced by
Short array syntax must be used to define arrays
Loading history...
57
                'bar' => 'baz',
58
                'tags' => array('foo', 'bar'),
0 ignored issues
show
Coding Style introduced by
Short array syntax must be used to define arrays
Loading history...
59
                'timestamp' => 1234567890,
60
                'someClass' => $someClass
61
            ),
62
            'context' =>  array(
0 ignored issues
show
Coding Style introduced by
Short array syntax must be used to define arrays
Loading history...
63
                'exception' => $ex,
64
            ),
65
        );
66
        $formatted = $formatter->format($input);
67
        unset($formatted['context']['exception']['trace'], $formatted['context']['exception']['previous']);
68
69
        $this->assertEquals(array(
0 ignored issues
show
Coding Style introduced by
Short array syntax must be used to define arrays
Loading history...
70
                'level_name' => 'WARNING',
71
                'channel' => 'test',
72
                'message' => 'foo',
73
                'datetime' => date('Y-m-d'),
74
                'context' =>  array(
0 ignored issues
show
Coding Style introduced by
Short array syntax must be used to define arrays
Loading history...
75
                    'exception' => array(
0 ignored issues
show
Coding Style introduced by
Short array syntax must be used to define arrays
Loading history...
76
                        'class' => get_class($ex),
77
                        'message' => $ex->getMessage(),
78
                        'code' => $ex->getCode(),
79
                        'file' => $ex->getFile().':'.$ex->getLine(),
80
                    )
81
                ),
82
                'extra' => array(),
0 ignored issues
show
Coding Style introduced by
Short array syntax must be used to define arrays
Loading history...
83
                'tags' => array('foo', 'bar'),
0 ignored issues
show
Coding Style introduced by
Short array syntax must be used to define arrays
Loading history...
84
                'timestamp' => 1234567890,
85
                'custom_data' => array('bar' => 'baz', 'someClass' => '[object] (stdClass: {"foo":"bar"})'),
0 ignored issues
show
Coding Style introduced by
Short array syntax must be used to define arrays
Loading history...
86
            ), $formatted);
87
    }
88
}
89