ILIAS  release_5-2 Revision v5.2.25-18-g3f80b828510
Monolog\Formatter\JsonFormatterTest Class Reference
+ Inheritance diagram for Monolog\Formatter\JsonFormatterTest:
+ Collaboration diagram for Monolog\Formatter\JsonFormatterTest:

Public Member Functions

 testConstruct ()
 @covers Monolog\Formatter\JsonFormatter::__construct @covers Monolog\Formatter\JsonFormatter::getBatchMode @covers Monolog\Formatter\JsonFormatter::isAppendingNewlines More...
 
 testFormat ()
 @covers Monolog\Formatter\JsonFormatter::format More...
 
 testFormatBatch ()
 @covers Monolog\Formatter\JsonFormatter::formatBatch @covers Monolog\Formatter\JsonFormatter::formatBatchJson More...
 
 testFormatBatchNewlines ()
 @covers Monolog\Formatter\JsonFormatter::formatBatch @covers Monolog\Formatter\JsonFormatter::formatBatchNewlines More...
 
 testDefFormatWithException ()
 
 testDefFormatWithPreviousException ()
 

Additional Inherited Members

- Protected Member Functions inherited from Monolog\TestCase
 getRecord ($level=Logger::WARNING, $message='test', $context=array())
 
 getMultipleRecords ()
 
 getIdentityFormatter ()
 

Detailed Description

Definition at line 17 of file JsonFormatterTest.php.

Member Function Documentation

◆ testConstruct()

Monolog\Formatter\JsonFormatterTest::testConstruct ( )

@covers Monolog\Formatter\JsonFormatter::__construct @covers Monolog\Formatter\JsonFormatter::getBatchMode @covers Monolog\Formatter\JsonFormatter::isAppendingNewlines

Definition at line 24 of file JsonFormatterTest.php.

25 {
26 $formatter = new JsonFormatter();
27 $this->assertEquals(JsonFormatter::BATCH_MODE_JSON, $formatter->getBatchMode());
28 $this->assertEquals(true, $formatter->isAppendingNewlines());
29 $formatter = new JsonFormatter(JsonFormatter::BATCH_MODE_NEWLINES, false);
30 $this->assertEquals(JsonFormatter::BATCH_MODE_NEWLINES, $formatter->getBatchMode());
31 $this->assertEquals(false, $formatter->isAppendingNewlines());
32 }

References Monolog\Formatter\JsonFormatter\BATCH_MODE_JSON, and Monolog\Formatter\JsonFormatter\BATCH_MODE_NEWLINES.

◆ testDefFormatWithException()

Monolog\Formatter\JsonFormatterTest::testDefFormatWithException ( )

Definition at line 79 of file JsonFormatterTest.php.

80 {
81 $formatter = new JsonFormatter();
82 $exception = new \RuntimeException('Foo');
83 $message = $formatter->format(array(
84 'level_name' => 'CRITICAL',
85 'channel' => 'core',
86 'context' => array('exception' => $exception),
87 'datetime' => new \DateTime(),
88 'extra' => array(),
89 'message' => 'foobar',
90 ));
91
92 if (version_compare(PHP_VERSION, '5.4.0', '>=')) {
93 $path = substr(json_encode($exception->getFile(), JSON_UNESCAPED_SLASHES | JSON_UNESCAPED_UNICODE), 1, -1);
94 } else {
95 $path = substr(json_encode($exception->getFile()), 1, -1);
96 }
97 $this->assertEquals('{"level_name":"CRITICAL","channel":"core","context":{"exception":{"class":"RuntimeException","message":"'.$exception->getMessage().'","code":'.$exception->getCode().',"file":"'.$path.':'.$exception->getLine().'"}},"datetime":'.json_encode(new \DateTime()).',"extra":[],"message":"foobar"}'."\n", $message);
98 }
$path
Definition: aliased.php:25

References $path.

◆ testDefFormatWithPreviousException()

Monolog\Formatter\JsonFormatterTest::testDefFormatWithPreviousException ( )

Definition at line 100 of file JsonFormatterTest.php.

101 {
102 $formatter = new JsonFormatter();
103 $exception = new \RuntimeException('Foo', 0, new \LogicException('Wut?'));
104 $message = $formatter->format(array(
105 'level_name' => 'CRITICAL',
106 'channel' => 'core',
107 'context' => array('exception' => $exception),
108 'datetime' => new \DateTime(),
109 'extra' => array(),
110 'message' => 'foobar',
111 ));
112
113 if (version_compare(PHP_VERSION, '5.4.0', '>=')) {
114 $pathPrevious = substr(json_encode($exception->getPrevious()->getFile(), JSON_UNESCAPED_SLASHES | JSON_UNESCAPED_UNICODE), 1, -1);
115 $pathException = substr(json_encode($exception->getFile(), JSON_UNESCAPED_SLASHES | JSON_UNESCAPED_UNICODE), 1, -1);
116 } else {
117 $pathPrevious = substr(json_encode($exception->getPrevious()->getFile()), 1, -1);
118 $pathException = substr(json_encode($exception->getFile()), 1, -1);
119 }
120 $this->assertEquals('{"level_name":"CRITICAL","channel":"core","context":{"exception":{"class":"RuntimeException","message":"'.$exception->getMessage().'","code":'.$exception->getCode().',"file":"'.$pathException.':'.$exception->getLine().'","previous":{"class":"LogicException","message":"'.$exception->getPrevious()->getMessage().'","code":'.$exception->getPrevious()->getCode().',"file":"'.$pathPrevious.':'.$exception->getPrevious()->getLine().'"}}},"datetime":'.json_encode(new \DateTime()).',"extra":[],"message":"foobar"}'."\n", $message);
121 }

◆ testFormat()

Monolog\Formatter\JsonFormatterTest::testFormat ( )

@covers Monolog\Formatter\JsonFormatter::format

Definition at line 37 of file JsonFormatterTest.php.

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 }
getRecord($level=Logger::WARNING, $message='test', $context=array())
Definition: TestCase.php:19

References Monolog\Formatter\JsonFormatter\BATCH_MODE_JSON, and Monolog\TestCase\getRecord().

+ Here is the call graph for this function:

◆ testFormatBatch()

Monolog\Formatter\JsonFormatterTest::testFormatBatch ( )

@covers Monolog\Formatter\JsonFormatter::formatBatch @covers Monolog\Formatter\JsonFormatter::formatBatchJson

Definition at line 52 of file JsonFormatterTest.php.

53 {
54 $formatter = new JsonFormatter();
55 $records = array(
58 );
59 $this->assertEquals(json_encode($records), $formatter->formatBatch($records));
60 }
const WARNING
Exceptional occurrences that are not errors.
Definition: Logger.php:52
const DEBUG
Detailed debug information.
Definition: Logger.php:32
$records
Definition: simple_test.php:22

References $records, Monolog\Logger\DEBUG, Monolog\TestCase\getRecord(), and Monolog\Logger\WARNING.

+ Here is the call graph for this function:

◆ testFormatBatchNewlines()

Monolog\Formatter\JsonFormatterTest::testFormatBatchNewlines ( )

@covers Monolog\Formatter\JsonFormatter::formatBatch @covers Monolog\Formatter\JsonFormatter::formatBatchNewlines

Definition at line 66 of file JsonFormatterTest.php.

67 {
68 $formatter = new JsonFormatter(JsonFormatter::BATCH_MODE_NEWLINES);
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 }

References $records, Monolog\Formatter\JsonFormatter\BATCH_MODE_NEWLINES, Monolog\Logger\DEBUG, Monolog\TestCase\getRecord(), and Monolog\Logger\WARNING.

+ Here is the call graph for this function:

The documentation for this class was generated from the following file: