JsonDateAwareFormatterTest::dataFormat()   A
last analyzed

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 10
c 0
b 0
f 0
1
<?php
2
3
namespace Graze\Monolog\Formatter;
4
5
use Monolog\TestCase;
6
7
class JsonDateAwareFormatterTest extends TestCase
8
{
9
    /**
10
     * @param mixed $data
11
     *
12
     * @return string
13
     */
14
    public function encodeJson($data)
15
    {
16
        if (version_compare(PHP_VERSION, '5.4.0', '>=')) {
17
            return json_encode($data, JSON_UNESCAPED_SLASHES | JSON_UNESCAPED_UNICODE);
18
        }
19
20
        return json_encode($data);
21
    }
22
23
    /**
24
     * @return array
25
     */
26
    public function dataFormat()
27
    {
28
        return [
29
            [['foo' => 'bar'], $this->encodeJson(['foo' => 'bar'])],
30
            [['timestamp' => new \DateTime('@0')], $this->encodeJson(['timestamp' => '1970-01-01 00:00:00'])],
31
        ];
32
    }
33
34
    /**
35
     * @dataProvider dataFormat
36
     *
37
     * @param array  $input
38
     * @param string $expected
39
     */
40
    public function testFormat(array $input, $expected)
41
    {
42
        $formatter = new JsonDateAwareFormatter();
43
        $this->assertEquals($expected, $formatter->format($input));
44
    }
45
46
    public function testFormatBatch()
47
    {
48
        $formatter = new JsonDateAwareFormatter();
49
        $records = [
50
            ['foo' => 'bar'],
51
            ['foo2' => 'bar2'],
52
        ];
53
        $this->assertEquals($this->encodeJson($records), $formatter->formatBatch($records));
54
    }
55
}
56