ILIAS  release_5-1 Revision 5.0.0-5477-g43f3e3fab5f
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 ()
 

Detailed Description

Definition at line 4 of file ScalarFormatterTest.php.

Member Function Documentation

◆ buildTrace()

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

Definition at line 11 of file ScalarFormatterTest.php.

12 {
13 $data = array();
14 $trace = $e->getTrace();
15 foreach ($trace as $frame) {
16 if (isset($frame['file'])) {
17 $data[] = $frame['file'].':'.$frame['line'];
18 } else {
19 $data[] = json_encode($frame);
20 }
21 }
22
23 return $data;
24 }
$data

References $data.

◆ encodeJson()

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

Definition at line 26 of file ScalarFormatterTest.php.

27 {
28 if (version_compare(PHP_VERSION, '5.4.0', '>=')) {
29 return json_encode($data, JSON_UNESCAPED_SLASHES | JSON_UNESCAPED_UNICODE);
30 }
31
32 return json_encode($data);
33 }

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 6 of file ScalarFormatterTest.php.

7 {
8 $this->formatter = new ScalarFormatter();
9 }

◆ testFormat()

Monolog\Formatter\ScalarFormatterTest::testFormat ( )

Definition at line 35 of file ScalarFormatterTest.php.

36 {
37 $exception = new \Exception('foo');
38 $formatted = $this->formatter->format(array(
39 'foo' => 'string',
40 'bar' => 1,
41 'baz' => false,
42 'bam' => array(1, 2, 3),
43 'bat' => array('foo' => 'bar'),
44 'bap' => \DateTime::createFromFormat(\DateTime::ISO8601, '1970-01-01T00:00:00+0000'),
45 'ban' => $exception
46 ));
47
48 $this->assertSame(array(
49 'foo' => 'string',
50 'bar' => 1,
51 'baz' => false,
52 'bam' => $this->encodeJson(array(1, 2, 3)),
53 'bat' => $this->encodeJson(array('foo' => 'bar')),
54 'bap' => '1970-01-01 00:00:00',
55 'ban' => $this->encodeJson(array(
56 'class' => get_class($exception),
57 'message' => $exception->getMessage(),
58 'code' => $exception->getCode(),
59 'file' => $exception->getFile() . ':' . $exception->getLine(),
60 'trace' => $this->buildTrace($exception)
61 ))
62 ), $formatted);
63 }

References Monolog\Formatter\ScalarFormatterTest\encodeJson().

+ Here is the call graph for this function:

◆ testFormatWithErrorContext()

Monolog\Formatter\ScalarFormatterTest::testFormatWithErrorContext ( )

Definition at line 65 of file ScalarFormatterTest.php.

66 {
67 $context = array('file' => 'foo', 'line' => 1);
68 $formatted = $this->formatter->format(array(
69 'context' => $context
70 ));
71
72 $this->assertSame(array(
73 'context' => $this->encodeJson($context)
74 ), $formatted);
75 }

References Monolog\Formatter\ScalarFormatterTest\encodeJson().

+ Here is the call graph for this function:

◆ testFormatWithExceptionContext()

Monolog\Formatter\ScalarFormatterTest::testFormatWithExceptionContext ( )

Definition at line 77 of file ScalarFormatterTest.php.

78 {
79 $exception = new \Exception('foo');
80 $formatted = $this->formatter->format(array(
81 'context' => array(
82 'exception' => $exception
83 )
84 ));
85
86 $this->assertSame(array(
87 'context' => $this->encodeJson(array(
88 'exception' => array(
89 'class' => get_class($exception),
90 'message' => $exception->getMessage(),
91 'code' => $exception->getCode(),
92 'file' => $exception->getFile() . ':' . $exception->getLine(),
93 'trace' => $this->buildTrace($exception)
94 )
95 ))
96 ), $formatted);
97 }

References Monolog\Formatter\ScalarFormatterTest\encodeJson().

+ Here is the call graph for this function:

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