ILIAS  release_5-1 Revision 5.0.0-5477-g43f3e3fab5f
JsonFormatterTest.php
Go to the documentation of this file.
1<?php
2
3/*
4 * This file is part of the Monolog package.
5 *
6 * (c) Jordi Boggiano <j.boggiano@seld.be>
7 *
8 * For the full copyright and license information, please view the LICENSE
9 * file that was distributed with this source code.
10 */
11
12namespace Monolog\Formatter;
13
16
18{
24 public function testConstruct()
25 {
26 $formatter = new JsonFormatter();
27 $this->assertEquals(JsonFormatter::BATCH_MODE_JSON, $formatter->getBatchMode());
28 $this->assertEquals(true, $formatter->isAppendingNewlines());
30 $this->assertEquals(JsonFormatter::BATCH_MODE_NEWLINES, $formatter->getBatchMode());
31 $this->assertEquals(false, $formatter->isAppendingNewlines());
32 }
33
37 public function testFormat()
38 {
39 $formatter = new JsonFormatter();
40 $record = $this->getRecord();
41 $this->assertEquals(json_encode($record)."\n", $formatter->format($record));
42
43 $formatter = new JsonFormatter(JsonFormatter::BATCH_MODE_JSON, false);
44 $record = $this->getRecord();
45 $this->assertEquals(json_encode($record), $formatter->format($record));
46 }
47
52 public function testFormatBatch()
53 {
54 $formatter = new JsonFormatter();
55 $records = array(
58 );
59 $this->assertEquals(json_encode($records), $formatter->formatBatch($records));
60 }
61
66 public function testFormatBatchNewlines()
67 {
69 $records = $expected = array(
72 );
73 array_walk($expected, function (&$value, $key) {
74 $value = json_encode($value);
75 });
76 $this->assertEquals(implode("\n", $expected), $formatter->formatBatch($records));
77 }
78}
testFormatBatch()
@covers Monolog\Formatter\JsonFormatter::formatBatch @covers Monolog\Formatter\JsonFormatter::formatB...
testFormat()
@covers Monolog\Formatter\JsonFormatter::format
testConstruct()
@covers Monolog\Formatter\JsonFormatter::__construct @covers Monolog\Formatter\JsonFormatter::getBatc...
testFormatBatchNewlines()
@covers Monolog\Formatter\JsonFormatter::formatBatch @covers Monolog\Formatter\JsonFormatter::formatB...
Encodes whatever record data is passed to it as json.
Monolog log channel.
Definition: Logger.php:28
const WARNING
Exceptional occurrences that are not errors.
Definition: Logger.php:52
const DEBUG
Detailed debug information.
Definition: Logger.php:32
getRecord($level=Logger::WARNING, $message='test', $context=array())
Definition: TestCase.php:19
$records
Definition: simple_test.php:17