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

JsonDateAwareFormatterTest::dataFormat()   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
namespace Graze\Monolog\Formatter;
3
4
use Monolog\TestCase;
5
6
class JsonDateAwareFormatterTest extends TestCase
7
{
8
9
    public function encodeJson($data)
0 ignored issues
show
introduced by
Function has return keyword but no doc block
Loading history...
10
    {
11
        if (version_compare(PHP_VERSION, '5.4.0', '>=')) {
12
            return json_encode($data, JSON_UNESCAPED_SLASHES | JSON_UNESCAPED_UNICODE);
13
        }
14
15
        return json_encode($data);
16
    }
17
18
    public function dataFormat()
0 ignored issues
show
introduced by
Function has return keyword but no doc block
Loading history...
19
    {
20
        return array(
0 ignored issues
show
Coding Style introduced by
Short array syntax must be used to define arrays
Loading history...
21
            array(array('foo'=>'bar'), $this->encodeJson(array('foo'=>'bar'))),
0 ignored issues
show
Coding Style introduced by
Short array syntax must be used to define arrays
Loading history...
22
            array(array('timestamp'=> new \DateTime('@0')), $this->encodeJson(array('timestamp' => '1970-01-01 00:00:00')))
0 ignored issues
show
Coding Style introduced by
Short array syntax must be used to define arrays
Loading history...
23
        );
24
    }
25
26
    /**
27
     * @dataProvider dataFormat
28
     * @param array $input
29
     * @param string $expected
30
     */
31
    public function testFormat(array $input, $expected)
32
    {
33
        $formatter = new JsonDateAwareFormatter();
34
        $this->assertEquals($expected, $formatter->format($input));
35
    }
36
37
    public function testFormatBatch()
38
    {
39
        $formatter = new JsonDateAwareFormatter();
40
        $records = array(
0 ignored issues
show
Coding Style introduced by
Short array syntax must be used to define arrays
Loading history...
41
            array('foo'=>'bar'),
0 ignored issues
show
Coding Style introduced by
Short array syntax must be used to define arrays
Loading history...
42
            array('foo2'=>'bar2'),
0 ignored issues
show
Coding Style introduced by
Short array syntax must be used to define arrays
Loading history...
43
        );
44
        $this->assertEquals($this->encodeJson($records), $formatter->formatBatch($records));
45
    }
46
}
47