Monolog
More...
◆ testBatchFormat()
Monolog\Formatter\NormalizerFormatterTest::testBatchFormat |
( |
| ) |
|
Definition at line 81 of file NormalizerFormatterTest.php.
83 $formatter =
new NormalizerFormatter(
'Y-m-d');
84 $formatted = $formatter->formatBatch(array(
86 'level_name' =>
'CRITICAL',
90 'datetime' =>
new \DateTime,
94 'level_name' =>
'WARNING',
98 'datetime' =>
new \DateTime,
102 $this->assertEquals(array(
104 'level_name' =>
'CRITICAL',
107 'context' => array(),
108 'datetime' => date(
'Y-m-d'),
112 'level_name' =>
'WARNING',
115 'context' => array(),
116 'datetime' => date(
'Y-m-d'),
◆ testExceptionTraceWithArgs()
Monolog\Formatter\NormalizerFormatterTest::testExceptionTraceWithArgs |
( |
| ) |
|
Definition at line 193 of file NormalizerFormatterTest.php.
References $result.
195 if (defined(
'HHVM_VERSION')) {
196 $this->markTestSkipped(
'Not supported in HHVM since it detects errors differently');
201 set_error_handler(
function ($errno, $errstr, $errfile, $errline) {
202 throw new \ErrorException($errstr, 0, $errno, $errfile, $errline);
207 $resource = fopen(
'php://memory',
'rw+');
208 fwrite($resource,
'test_resource');
209 $wrappedResource =
new TestFooNorm;
210 $wrappedResource->foo = $resource;
212 array_keys($wrappedResource);
214 restore_error_handler();
217 $formatter =
new NormalizerFormatter();
218 $record = array(
'context' => array(
'exception' => $e));
219 $result = $formatter->format($record);
222 '%"resource":"\[resource\]"%',
223 $result[
'context'][
'exception'][
'trace'][0]
226 if (version_compare(PHP_VERSION,
'5.5.0',
'>=')) {
227 $pattern =
'%"wrappedResource":"\[object\] \(Monolog\\\\\\\\Formatter\\\\\\\\TestFooNorm: \)"%';
229 $pattern =
'%\\\\"foo\\\\":null%';
235 $result[
'context'][
'exception'][
'trace'][0]
◆ testFormat()
Monolog\Formatter\NormalizerFormatterTest::testFormat |
( |
| ) |
|
Definition at line 19 of file NormalizerFormatterTest.php.
21 $formatter =
new NormalizerFormatter(
'Y-m-d');
22 $formatted = $formatter->format(array(
23 'level_name' =>
'ERROR',
26 'datetime' =>
new \DateTime,
27 'extra' => array(
'foo' =>
new TestFooNorm,
'bar' =>
new TestBarNorm,
'baz' => array(),
'res' => fopen(
'php://memory',
'rb')),
37 $this->assertEquals(array(
38 'level_name' =>
'ERROR',
41 'datetime' => date(
'Y-m-d'),
43 'foo' =>
'[object] (Monolog\\Formatter\\TestFooNorm: {"foo":"foo"})',
44 'bar' =>
'[object] (Monolog\\Formatter\\TestBarNorm: bar)',
46 'res' =>
'[resource]',
◆ testFormatExceptions()
Monolog\Formatter\NormalizerFormatterTest::testFormatExceptions |
( |
| ) |
|
Definition at line 58 of file NormalizerFormatterTest.php.
60 $formatter =
new NormalizerFormatter(
'Y-m-d');
61 $e = new \LogicException(
'bar');
62 $e2 = new \RuntimeException(
'foo', 0, $e);
63 $formatted = $formatter->format(array(
67 $this->assertGreaterThan(5, count($formatted[
'exception'][
'trace']));
68 $this->assertTrue(isset($formatted[
'exception'][
'previous']));
69 unset($formatted[
'exception'][
'trace'], $formatted[
'exception'][
'previous']);
71 $this->assertEquals(array(
73 'class' => get_class($e2),
74 'message' => $e2->getMessage(),
75 'code' => $e2->getCode(),
76 'file' => $e2->getFile().
':'.$e2->getLine(),
◆ testIgnoresInvalidTypes()
Monolog\Formatter\NormalizerFormatterTest::testIgnoresInvalidTypes |
( |
| ) |
|
Definition at line 153 of file NormalizerFormatterTest.php.
References $file, and $res.
156 $resource = fopen(__FILE__,
'r');
160 set_error_handler(
function ($level, $message,
$file, $line, $context) use ($that) {
161 if (error_reporting() & $level) {
162 restore_error_handler();
163 $that->fail(
"$message should not be raised");
167 $formatter =
new NormalizerFormatter();
168 $reflMethod = new \ReflectionMethod($formatter,
'toJson');
169 $reflMethod->setAccessible(
true);
170 $res = $reflMethod->invoke($formatter, array($resource),
true);
172 restore_error_handler();
174 $this->assertEquals(@json_encode(array($resource)),
$res);
◆ testIgnoresRecursiveObjectReferences()
Monolog\Formatter\NormalizerFormatterTest::testIgnoresRecursiveObjectReferences |
( |
| ) |
|
Test issue #137.
Definition at line 125 of file NormalizerFormatterTest.php.
References $file, and $res.
128 $foo = new \stdClass();
129 $bar = new \stdClass();
136 set_error_handler(
function ($level, $message,
$file, $line, $context) use ($that) {
137 if (error_reporting() & $level) {
138 restore_error_handler();
139 $that->fail(
"$message should not be raised");
143 $formatter =
new NormalizerFormatter();
144 $reflMethod = new \ReflectionMethod($formatter,
'toJson');
145 $reflMethod->setAccessible(
true);
146 $res = $reflMethod->invoke($formatter, array($foo, $bar),
true);
148 restore_error_handler();
150 $this->assertEquals(@json_encode(array($foo, $bar)),
$res);
◆ testThrowsOnInvalidEncoding()
Monolog\Formatter\NormalizerFormatterTest::testThrowsOnInvalidEncoding |
( |
| ) |
|
RuntimeException
Definition at line 180 of file NormalizerFormatterTest.php.
References $res.
182 $formatter =
new NormalizerFormatter();
183 $reflMethod = new \ReflectionMethod($formatter,
'toJson');
184 $reflMethod->setAccessible(
true);
187 $res = $reflMethod->invoke($formatter, array(
'message' =>
"\xB1\x31"));
188 if (PHP_VERSION_ID < 50500 &&
$res ===
'{"message":null}') {
189 throw new \RuntimeException(
'PHP 5.3/5.4 throw a warning and null the value instead of returning false entirely');
The documentation for this class was generated from the following file: