ILIAS  release_5-3 Revision v5.3.23-19-g915713cf615
Monolog\Formatter\ScalarFormatterTest Class Reference
+ Inheritance diagram for Monolog\Formatter\ScalarFormatterTest:
+ Collaboration diagram for Monolog\Formatter\ScalarFormatterTest:

Public Member Functions

 setUp ()
 
 buildTrace (\Exception $e)
 
 encodeJson ($data)
 
 testFormat ()
 
 testFormatWithErrorContext ()
 
 testFormatWithExceptionContext ()
 

Private Attributes

 $formatter
 

Detailed Description

Definition at line 14 of file ScalarFormatterTest.php.

Member Function Documentation

◆ buildTrace()

Monolog\Formatter\ScalarFormatterTest::buildTrace ( \Exception  $e)

Definition at line 23 of file ScalarFormatterTest.php.

24 {
25 $data = array();
26 $trace = $e->getTrace();
27 foreach ($trace as $frame) {
28 if (isset($frame['file'])) {
29 $data[] = $frame['file'].':'.$frame['line'];
30 } else {
31 $data[] = json_encode($frame);
32 }
33 }
34
35 return $data;
36 }

References $data.

◆ encodeJson()

Monolog\Formatter\ScalarFormatterTest::encodeJson (   $data)

Definition at line 38 of file ScalarFormatterTest.php.

39 {
40 if (version_compare(PHP_VERSION, '5.4.0', '>=')) {
41 return json_encode($data, JSON_UNESCAPED_SLASHES | JSON_UNESCAPED_UNICODE);
42 }
43
44 return json_encode($data);
45 }

References $data.

Referenced by Monolog\Formatter\ScalarFormatterTest\testFormat(), Monolog\Formatter\ScalarFormatterTest\testFormatWithErrorContext(), and Monolog\Formatter\ScalarFormatterTest\testFormatWithExceptionContext().

+ Here is the caller graph for this function:

◆ setUp()

Monolog\Formatter\ScalarFormatterTest::setUp ( )

Definition at line 18 of file ScalarFormatterTest.php.

19 {
20 $this->formatter = new ScalarFormatter();
21 }

◆ testFormat()

Monolog\Formatter\ScalarFormatterTest::testFormat ( )

Definition at line 47 of file ScalarFormatterTest.php.

48 {
49 $exception = new \Exception('foo');
50 $formatted = $this->formatter->format(array(
51 'foo' => 'string',
52 'bar' => 1,
53 'baz' => false,
54 'bam' => array(1, 2, 3),
55 'bat' => array('foo' => 'bar'),
56 'bap' => \DateTime::createFromFormat(\DateTime::ISO8601, '1970-01-01T00:00:00+0000'),
57 'ban' => $exception,
58 ));
59
60 $this->assertSame(array(
61 'foo' => 'string',
62 'bar' => 1,
63 'baz' => false,
64 'bam' => $this->encodeJson(array(1, 2, 3)),
65 'bat' => $this->encodeJson(array('foo' => 'bar')),
66 'bap' => '1970-01-01 00:00:00',
67 'ban' => $this->encodeJson(array(
68 'class' => get_class($exception),
69 'message' => $exception->getMessage(),
70 'code' => $exception->getCode(),
71 'file' => $exception->getFile() . ':' . $exception->getLine(),
72 'trace' => $this->buildTrace($exception),
73 )),
74 ), $formatted);
75 }

References Monolog\Formatter\ScalarFormatterTest\encodeJson().

+ Here is the call graph for this function:

◆ testFormatWithErrorContext()

Monolog\Formatter\ScalarFormatterTest::testFormatWithErrorContext ( )

Definition at line 77 of file ScalarFormatterTest.php.

78 {
79 $context = array('file' => 'foo', 'line' => 1);
80 $formatted = $this->formatter->format(array(
81 'context' => $context,
82 ));
83
84 $this->assertSame(array(
85 'context' => $this->encodeJson($context),
86 ), $formatted);
87 }

References Monolog\Formatter\ScalarFormatterTest\encodeJson().

+ Here is the call graph for this function:

◆ testFormatWithExceptionContext()

Monolog\Formatter\ScalarFormatterTest::testFormatWithExceptionContext ( )

Definition at line 89 of file ScalarFormatterTest.php.

90 {
91 $exception = new \Exception('foo');
92 $formatted = $this->formatter->format(array(
93 'context' => array(
94 'exception' => $exception,
95 ),
96 ));
97
98 $this->assertSame(array(
99 'context' => $this->encodeJson(array(
100 'exception' => array(
101 'class' => get_class($exception),
102 'message' => $exception->getMessage(),
103 'code' => $exception->getCode(),
104 'file' => $exception->getFile() . ':' . $exception->getLine(),
105 'trace' => $this->buildTrace($exception),
106 ),
107 )),
108 ), $formatted);
109 }

References Monolog\Formatter\ScalarFormatterTest\encodeJson().

+ Here is the call graph for this function:

Field Documentation

◆ $formatter

Monolog\Formatter\ScalarFormatterTest::$formatter
private

Definition at line 16 of file ScalarFormatterTest.php.


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