ILIAS  release_5-1 Revision 5.0.0-5477-g43f3e3fab5f
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 ()
 
 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 144 of file LineFormatterTest.php.

145 {
146 $formatter = new LineFormatter(null, 'Y-m-d');
147 $message = $formatter->formatBatch(array(
148 array(
149 'level_name' => 'CRITICAL',
150 'channel' => 'test',
151 'message' => 'bar',
152 'context' => array(),
153 'datetime' => new \DateTime,
154 'extra' => array(),
155 ),
156 array(
157 'level_name' => 'WARNING',
158 'channel' => 'log',
159 'message' => 'foo',
160 'context' => array(),
161 'datetime' => new \DateTime,
162 'extra' => array(),
163 ),
164 ));
165 $this->assertEquals('['.date('Y-m-d').'] test.CRITICAL: bar [] []'."\n".'['.date('Y-m-d').'] log.WARNING: foo [] []'."\n", $message);
166 }

◆ 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 }

◆ 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 }

◆ 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 }

◆ testDefFormatWithException()

Monolog\Formatter\LineFormatterTest::testDefFormatWithException ( )

Definition at line 109 of file LineFormatterTest.php.

110 {
111 $formatter = new LineFormatter(null, 'Y-m-d');
112 $message = $formatter->format(array(
113 'level_name' => 'CRITICAL',
114 'channel' => 'core',
115 'context' => array('exception' => new \RuntimeException('Foo')),
116 'datetime' => new \DateTime,
117 'extra' => array(),
118 'message' => 'foobar',
119 ));
120
121 $path = str_replace('\\/', '/', json_encode(__FILE__));
122
123 $this->assertEquals('['.date('Y-m-d').'] core.CRITICAL: foobar {"exception":"[object] (RuntimeException(code: 0): Foo at '.substr($path, 1, -1).':'.(__LINE__-8).')"} []'."\n", $message);
124 }
$path
Definition: index.php:22

References $path.

◆ testDefFormatWithObject()

Monolog\Formatter\LineFormatterTest::testDefFormatWithObject ( )

Definition at line 94 of file LineFormatterTest.php.

95 {
96 $formatter = new LineFormatter(null, 'Y-m-d');
97 $message = $formatter->format(array(
98 'level_name' => 'ERROR',
99 'channel' => 'meh',
100 'context' => array(),
101 'datetime' => new \DateTime,
102 'extra' => array('foo' => new TestFoo, 'bar' => new TestBar, 'baz' => array(), 'res' => fopen('php://memory', 'rb')),
103 'message' => 'foobar',
104 ));
105
106 $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]"}'."\n", $message);
107 }

◆ testDefFormatWithPreviousException()

Monolog\Formatter\LineFormatterTest::testDefFormatWithPreviousException ( )

Definition at line 126 of file LineFormatterTest.php.

127 {
128 $formatter = new LineFormatter(null, 'Y-m-d');
129 $previous = new \LogicException('Wut?');
130 $message = $formatter->format(array(
131 'level_name' => 'CRITICAL',
132 'channel' => 'core',
133 'context' => array('exception' => new \RuntimeException('Foo', 0, $previous)),
134 'datetime' => new \DateTime,
135 'extra' => array(),
136 'message' => 'foobar',
137 ));
138
139 $path = str_replace('\\/', '/', json_encode(__FILE__));
140
141 $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);
142 }

References $path.

◆ 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 }

◆ 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 }

◆ testFormatShouldNotStripInlineLineBreaksWhenFlagIsSet()

Monolog\Formatter\LineFormatterTest::testFormatShouldNotStripInlineLineBreaksWhenFlagIsSet ( )

Definition at line 182 of file LineFormatterTest.php.

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

◆ testFormatShouldStripInlineLineBreaks()

Monolog\Formatter\LineFormatterTest::testFormatShouldStripInlineLineBreaks ( )

Definition at line 168 of file LineFormatterTest.php.

169 {
170 $formatter = new LineFormatter(null, 'Y-m-d');
171 $message = $formatter->format(
172 array(
173 'message' => "foo\nbar",
174 'context' => array(),
175 'extra' => array(),
176 )
177 );
178
179 $this->assertRegExp('/foo bar/', $message);
180 }

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