ILIAS  release_5-3 Revision v5.3.23-19-g915713cf615
Monolog\Formatter\LineFormatterTest Class Reference

@covers Monolog\Formatter\LineFormatter More...

+ Inheritance diagram for Monolog\Formatter\LineFormatterTest:
+ Collaboration diagram for Monolog\Formatter\LineFormatterTest:

Public Member Functions

 testDefFormatWithString ()
 
 testDefFormatWithArrayContext ()
 
 testDefFormatExtras ()
 
 testFormatExtras ()
 
 testContextAndExtraOptionallyNotShownIfEmpty ()
 
 testContextAndExtraReplacement ()
 
 testDefFormatWithObject ()
 
 testDefFormatWithException ()
 
 testDefFormatWithPreviousException ()
 
 testBatchFormat ()
 
 testFormatShouldStripInlineLineBreaks ()
 
 testFormatShouldNotStripInlineLineBreaksWhenFlagIsSet ()
 

Detailed Description

@covers Monolog\Formatter\LineFormatter

Definition at line 17 of file LineFormatterTest.php.

Member Function Documentation

◆ testBatchFormat()

Monolog\Formatter\LineFormatterTest::testBatchFormat ( )

Definition at line 158 of file LineFormatterTest.php.

159 {
160 $formatter = new LineFormatter(null, 'Y-m-d');
161 $message = $formatter->formatBatch(array(
162 array(
163 'level_name' => 'CRITICAL',
164 'channel' => 'test',
165 'message' => 'bar',
166 'context' => array(),
167 'datetime' => new \DateTime,
168 'extra' => array(),
169 ),
170 array(
171 'level_name' => 'WARNING',
172 'channel' => 'log',
173 'message' => 'foo',
174 'context' => array(),
175 'datetime' => new \DateTime,
176 'extra' => array(),
177 ),
178 ));
179 $this->assertEquals('['.date('Y-m-d').'] test.CRITICAL: bar [] []'."\n".'['.date('Y-m-d').'] log.WARNING: foo [] []'."\n", $message);
180 }
date( 'd-M-Y', $objPHPExcel->getProperties() ->getCreated())
catch(Exception $e) $message

References $message, and date.

◆ testContextAndExtraOptionallyNotShownIfEmpty()

Monolog\Formatter\LineFormatterTest::testContextAndExtraOptionallyNotShownIfEmpty ( )

Definition at line 80 of file LineFormatterTest.php.

81 {
82 $formatter = new LineFormatter(null, 'Y-m-d', false, true);
83 $message = $formatter->format(array(
84 'level_name' => 'ERROR',
85 'channel' => 'meh',
86 'context' => array(),
87 'datetime' => new \DateTime,
88 'extra' => array(),
89 'message' => 'log',
90 ));
91 $this->assertEquals('['.date('Y-m-d').'] meh.ERROR: log '."\n", $message);
92 }

References $message, and date.

◆ testContextAndExtraReplacement()

Monolog\Formatter\LineFormatterTest::testContextAndExtraReplacement ( )

Definition at line 94 of file LineFormatterTest.php.

95 {
96 $formatter = new LineFormatter('%context.foo% => %extra.foo%');
97 $message = $formatter->format(array(
98 'level_name' => 'ERROR',
99 'channel' => 'meh',
100 'context' => array('foo' => 'bar'),
101 'datetime' => new \DateTime,
102 'extra' => array('foo' => 'xbar'),
103 'message' => 'log',
104 ));
105 $this->assertEquals('bar => xbar', $message);
106 }

References $message.

◆ testDefFormatExtras()

Monolog\Formatter\LineFormatterTest::testDefFormatExtras ( )

Definition at line 52 of file LineFormatterTest.php.

53 {
54 $formatter = new LineFormatter(null, 'Y-m-d');
55 $message = $formatter->format(array(
56 'level_name' => 'ERROR',
57 'channel' => 'meh',
58 'context' => array(),
59 'datetime' => new \DateTime,
60 'extra' => array('ip' => '127.0.0.1'),
61 'message' => 'log',
62 ));
63 $this->assertEquals('['.date('Y-m-d').'] meh.ERROR: log [] {"ip":"127.0.0.1"}'."\n", $message);
64 }

References $message, and date.

◆ testDefFormatWithArrayContext()

Monolog\Formatter\LineFormatterTest::testDefFormatWithArrayContext ( )

Definition at line 33 of file LineFormatterTest.php.

34 {
35 $formatter = new LineFormatter(null, 'Y-m-d');
36 $message = $formatter->format(array(
37 'level_name' => 'ERROR',
38 'channel' => 'meh',
39 'message' => 'foo',
40 'datetime' => new \DateTime,
41 'extra' => array(),
42 'context' => array(
43 'foo' => 'bar',
44 'baz' => 'qux',
45 'bool' => false,
46 'null' => null,
47 ),
48 ));
49 $this->assertEquals('['.date('Y-m-d').'] meh.ERROR: foo {"foo":"bar","baz":"qux","bool":false,"null":null} []'."\n", $message);
50 }

References $message, and date.

◆ testDefFormatWithException()

Monolog\Formatter\LineFormatterTest::testDefFormatWithException ( )

Definition at line 123 of file LineFormatterTest.php.

124 {
125 $formatter = new LineFormatter(null, 'Y-m-d');
126 $message = $formatter->format(array(
127 'level_name' => 'CRITICAL',
128 'channel' => 'core',
129 'context' => array('exception' => new \RuntimeException('Foo')),
130 'datetime' => new \DateTime,
131 'extra' => array(),
132 'message' => 'foobar',
133 ));
134
135 $path = str_replace('\\/', '/', json_encode(__FILE__));
136
137 $this->assertEquals('['.date('Y-m-d').'] core.CRITICAL: foobar {"exception":"[object] (RuntimeException(code: 0): Foo at '.substr($path, 1, -1).':'.(__LINE__ - 8).')"} []'."\n", $message);
138 }

References $message, $path, and date.

◆ testDefFormatWithObject()

Monolog\Formatter\LineFormatterTest::testDefFormatWithObject ( )

Definition at line 108 of file LineFormatterTest.php.

109 {
110 $formatter = new LineFormatter(null, 'Y-m-d');
111 $message = $formatter->format(array(
112 'level_name' => 'ERROR',
113 'channel' => 'meh',
114 'context' => array(),
115 'datetime' => new \DateTime,
116 'extra' => array('foo' => new TestFoo, 'bar' => new TestBar, 'baz' => array(), 'res' => fopen('php://memory', 'rb')),
117 'message' => 'foobar',
118 ));
119
120 $this->assertEquals('['.date('Y-m-d').'] meh.ERROR: foobar [] {"foo":"[object] (Monolog\\\\Formatter\\\\TestFoo: {\\"foo\\":\\"foo\\"})","bar":"[object] (Monolog\\\\Formatter\\\\TestBar: bar)","baz":[],"res":"[resource] (stream)"}'."\n", $message);
121 }

References $message, and date.

◆ testDefFormatWithPreviousException()

Monolog\Formatter\LineFormatterTest::testDefFormatWithPreviousException ( )

Definition at line 140 of file LineFormatterTest.php.

141 {
142 $formatter = new LineFormatter(null, 'Y-m-d');
143 $previous = new \LogicException('Wut?');
144 $message = $formatter->format(array(
145 'level_name' => 'CRITICAL',
146 'channel' => 'core',
147 'context' => array('exception' => new \RuntimeException('Foo', 0, $previous)),
148 'datetime' => new \DateTime,
149 'extra' => array(),
150 'message' => 'foobar',
151 ));
152
153 $path = str_replace('\\/', '/', json_encode(__FILE__));
154
155 $this->assertEquals('['.date('Y-m-d').'] core.CRITICAL: foobar {"exception":"[object] (RuntimeException(code: 0): Foo at '.substr($path, 1, -1).':'.(__LINE__ - 8).', LogicException(code: 0): Wut? at '.substr($path, 1, -1).':'.(__LINE__ - 12).')"} []'."\n", $message);
156 }

References $message, $path, and date.

◆ testDefFormatWithString()

Monolog\Formatter\LineFormatterTest::testDefFormatWithString ( )

Definition at line 19 of file LineFormatterTest.php.

20 {
21 $formatter = new LineFormatter(null, 'Y-m-d');
22 $message = $formatter->format(array(
23 'level_name' => 'WARNING',
24 'channel' => 'log',
25 'context' => array(),
26 'message' => 'foo',
27 'datetime' => new \DateTime,
28 'extra' => array(),
29 ));
30 $this->assertEquals('['.date('Y-m-d').'] log.WARNING: foo [] []'."\n", $message);
31 }

References $message, and date.

◆ testFormatExtras()

Monolog\Formatter\LineFormatterTest::testFormatExtras ( )

Definition at line 66 of file LineFormatterTest.php.

67 {
68 $formatter = new LineFormatter("[%datetime%] %channel%.%level_name%: %message% %context% %extra.file% %extra%\n", 'Y-m-d');
69 $message = $formatter->format(array(
70 'level_name' => 'ERROR',
71 'channel' => 'meh',
72 'context' => array(),
73 'datetime' => new \DateTime,
74 'extra' => array('ip' => '127.0.0.1', 'file' => 'test'),
75 'message' => 'log',
76 ));
77 $this->assertEquals('['.date('Y-m-d').'] meh.ERROR: log [] test {"ip":"127.0.0.1"}'."\n", $message);
78 }

References $message, and date.

◆ testFormatShouldNotStripInlineLineBreaksWhenFlagIsSet()

Monolog\Formatter\LineFormatterTest::testFormatShouldNotStripInlineLineBreaksWhenFlagIsSet ( )

Definition at line 196 of file LineFormatterTest.php.

197 {
198 $formatter = new LineFormatter(null, 'Y-m-d', true);
199 $message = $formatter->format(
200 array(
201 'message' => "foo\nbar",
202 'context' => array(),
203 'extra' => array(),
204 )
205 );
206
207 $this->assertRegExp('/foo\nbar/', $message);
208 }

References $message.

◆ testFormatShouldStripInlineLineBreaks()

Monolog\Formatter\LineFormatterTest::testFormatShouldStripInlineLineBreaks ( )

Definition at line 182 of file LineFormatterTest.php.

183 {
184 $formatter = new LineFormatter(null, 'Y-m-d');
185 $message = $formatter->format(
186 array(
187 'message' => "foo\nbar",
188 'context' => array(),
189 'extra' => array(),
190 )
191 );
192
193 $this->assertRegExp('/foo bar/', $message);
194 }

References $message.


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