ILIAS  release_5-4 Revision v5.4.26-12-gabc799a52e6
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 ()
 
 testDefFormatWithThrowable ()
 
 testNormalizeHandleLargeArraysWithExactly1000Items ()
 
 testNormalizeHandleLargeArrays ()
 

Private Member Functions

 assertContextContainsFormattedException ($expected, $actual)
 
 formatRecordWithExceptionInContext (JsonFormatter $formatter, $exception)
 
 formatExceptionFilePathWithLine ($exception)
 
 formatException ($exception, $previous=null)
 

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

◆ assertContextContainsFormattedException()

Monolog\Formatter\JsonFormatterTest::assertContextContainsFormattedException (   $expected,
  $actual 
)
private
Parameters
string$expected
string$actual

Definition at line 123 of file JsonFormatterTest.php.

124 {
125 $this->assertEquals(
126 '{"level_name":"CRITICAL","channel":"core","context":{"exception":'.$expected.'},"datetime":null,"extra":[],"message":"foobar"}'."\n",
127 $actual
128 );
129 }

Referenced by Monolog\Formatter\JsonFormatterTest\testDefFormatWithException(), Monolog\Formatter\JsonFormatterTest\testDefFormatWithPreviousException(), and Monolog\Formatter\JsonFormatterTest\testDefFormatWithThrowable().

+ Here is the caller graph for this function:

◆ formatException()

Monolog\Formatter\JsonFormatterTest::formatException (   $exception,
  $previous = null 
)
private
Parameters
\Exception | \Throwable$exception
null | string$previous
Returns
string

Definition at line 172 of file JsonFormatterTest.php.

173 {
174 $formattedException =
175 '{"class":"' . get_class($exception) .
176 '","message":"' . $exception->getMessage() .
177 '","code":' . $exception->getCode() .
178 ',"file":"' . $this->formatExceptionFilePathWithLine($exception) .
179 ($previous ? '","previous":' . $previous : '"') .
180 '}';
181 return $formattedException;
182 }

References Monolog\Formatter\JsonFormatterTest\formatExceptionFilePathWithLine().

Referenced by Monolog\Formatter\JsonFormatterTest\testDefFormatWithException(), Monolog\Formatter\JsonFormatterTest\testDefFormatWithPreviousException(), and Monolog\Formatter\JsonFormatterTest\testDefFormatWithThrowable().

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ formatExceptionFilePathWithLine()

Monolog\Formatter\JsonFormatterTest::formatExceptionFilePathWithLine (   $exception)
private
Parameters
\Exception | \Throwable$exception
Returns
string

Definition at line 155 of file JsonFormatterTest.php.

156 {
157 $options = 0;
158 if (version_compare(PHP_VERSION, '5.4.0', '>=')) {
159 $options = JSON_UNESCAPED_SLASHES | JSON_UNESCAPED_UNICODE;
160 }
161 $path = substr(json_encode($exception->getFile(), $options), 1, -1);
162 return $path . ':' . $exception->getLine();
163 }
$path
Definition: aliased.php:25

References PHPMailer\PHPMailer\$options, and $path.

Referenced by Monolog\Formatter\JsonFormatterTest\formatException().

+ Here is the caller graph for this function:

◆ formatRecordWithExceptionInContext()

Monolog\Formatter\JsonFormatterTest::formatRecordWithExceptionInContext ( JsonFormatter  $formatter,
  $exception 
)
private
Parameters
JsonFormatter$formatter
\Exception | \Throwable$exception
Returns
string

Definition at line 137 of file JsonFormatterTest.php.

138 {
139 $message = $formatter->format(array(
140 'level_name' => 'CRITICAL',
141 'channel' => 'core',
142 'context' => array('exception' => $exception),
143 'datetime' => null,
144 'extra' => array(),
145 'message' => 'foobar',
146 ));
147 return $message;
148 }
catch(Exception $e) $message

References $message, and Monolog\Formatter\JsonFormatter\format().

Referenced by Monolog\Formatter\JsonFormatterTest\testDefFormatWithException(), Monolog\Formatter\JsonFormatterTest\testDefFormatWithPreviousException(), and Monolog\Formatter\JsonFormatterTest\testDefFormatWithThrowable().

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ 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 $formattedException = $this->formatException($exception);
84
85 $message = $this->formatRecordWithExceptionInContext($formatter, $exception);
86
87 $this->assertContextContainsFormattedException($formattedException, $message);
88 }
formatException($exception, $previous=null)
assertContextContainsFormattedException($expected, $actual)
formatRecordWithExceptionInContext(JsonFormatter $formatter, $exception)

References $message, Monolog\Formatter\JsonFormatterTest\assertContextContainsFormattedException(), Monolog\Formatter\JsonFormatterTest\formatException(), and Monolog\Formatter\JsonFormatterTest\formatRecordWithExceptionInContext().

+ Here is the call graph for this function:

◆ testDefFormatWithPreviousException()

Monolog\Formatter\JsonFormatterTest::testDefFormatWithPreviousException ( )

Definition at line 90 of file JsonFormatterTest.php.

91 {
92 $formatter = new JsonFormatter();
93 $exception = new \RuntimeException('Foo', 0, new \LogicException('Wut?'));
94 $formattedPrevException = $this->formatException($exception->getPrevious());
95 $formattedException = $this->formatException($exception, $formattedPrevException);
96
97 $message = $this->formatRecordWithExceptionInContext($formatter, $exception);
98
99 $this->assertContextContainsFormattedException($formattedException, $message);
100 }

References $message, Monolog\Formatter\JsonFormatterTest\assertContextContainsFormattedException(), Monolog\Formatter\JsonFormatterTest\formatException(), and Monolog\Formatter\JsonFormatterTest\formatRecordWithExceptionInContext().

+ Here is the call graph for this function:

◆ testDefFormatWithThrowable()

Monolog\Formatter\JsonFormatterTest::testDefFormatWithThrowable ( )

Definition at line 102 of file JsonFormatterTest.php.

103 {
104 if (!class_exists('Error') || !is_subclass_of('Error', 'Throwable')) {
105 $this->markTestSkipped('Requires PHP >=7');
106 }
107
108 $formatter = new JsonFormatter();
109 $throwable = new \Error('Foo');
110 $formattedThrowable = $this->formatException($throwable);
111
112 $message = $this->formatRecordWithExceptionInContext($formatter, $throwable);
113
114 $this->assertContextContainsFormattedException($formattedThrowable, $message);
115 }

References $message, Monolog\Formatter\JsonFormatterTest\assertContextContainsFormattedException(), Monolog\Formatter\JsonFormatterTest\formatException(), and Monolog\Formatter\JsonFormatterTest\formatRecordWithExceptionInContext().

+ Here is the call graph for this function:

◆ 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:53
const DEBUG
Detailed debug information.
Definition: Logger.php:33
$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 }
$key
Definition: croninfo.php:18

References $key, $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:

◆ testNormalizeHandleLargeArrays()

Monolog\Formatter\JsonFormatterTest::testNormalizeHandleLargeArrays ( )

Definition at line 202 of file JsonFormatterTest.php.

203 {
204 $formatter = new NormalizerFormatter();
205 $largeArray = range(1, 2000);
206
207 $res = $formatter->format(array(
208 'level_name' => 'CRITICAL',
209 'channel' => 'test',
210 'message' => 'bar',
211 'context' => array($largeArray),
212 'datetime' => new \DateTime,
213 'extra' => array(),
214 ));
215
216 $this->assertCount(1001, $res['context'][0]);
217 $this->assertEquals('Over 1000 items (2000 total), aborting normalization', $res['context'][0]['...']);
218 }
foreach($_POST as $key=> $value) $res

References $res.

◆ testNormalizeHandleLargeArraysWithExactly1000Items()

Monolog\Formatter\JsonFormatterTest::testNormalizeHandleLargeArraysWithExactly1000Items ( )

Definition at line 184 of file JsonFormatterTest.php.

185 {
186 $formatter = new NormalizerFormatter();
187 $largeArray = range(1, 1000);
188
189 $res = $formatter->format(array(
190 'level_name' => 'CRITICAL',
191 'channel' => 'test',
192 'message' => 'bar',
193 'context' => array($largeArray),
194 'datetime' => new \DateTime,
195 'extra' => array(),
196 ));
197
198 $this->assertCount(1000, $res['context'][0]);
199 $this->assertArrayNotHasKey('...', $res['context'][0]);
200 }

References $res.


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