ILIAS  release_5-1 Revision 5.0.0-5477-g43f3e3fab5f
ChromePHPHandlerTest.php
Go to the documentation of this file.
1<?php
2
3/*
4 * This file is part of the Monolog package.
5 *
6 * (c) Jordi Boggiano <j.boggiano@seld.be>
7 *
8 * For the full copyright and license information, please view the LICENSE
9 * file that was distributed with this source code.
10 */
11
12namespace Monolog\Handler;
13
16
21{
22 protected function setUp()
23 {
25 $_SERVER['HTTP_USER_AGENT'] = 'Monolog Test; Chrome/1.0';
26 }
27
28 public function testHeaders()
29 {
30 $handler = new TestChromePHPHandler();
31 $handler->setFormatter($this->getIdentityFormatter());
32 $handler->handle($this->getRecord(Logger::DEBUG));
33 $handler->handle($this->getRecord(Logger::WARNING));
34
35 $expected = array(
36 'X-ChromeLogger-Data' => base64_encode(utf8_encode(json_encode(array(
37 'version' => ChromePHPHandler::VERSION,
38 'columns' => array('label', 'log', 'backtrace', 'type'),
39 'rows' => array(
40 'test',
41 'test',
42 ),
43 'request_uri' => '',
44 ))))
45 );
46
47 $this->assertEquals($expected, $handler->getHeaders());
48 }
49
50 public function testHeadersOverflow()
51 {
52 $handler = new TestChromePHPHandler();
53 $handler->handle($this->getRecord(Logger::DEBUG));
54 $handler->handle($this->getRecord(Logger::WARNING, str_repeat('a', 150*1024)));
55
56 // overflow chrome headers limit
57 $handler->handle($this->getRecord(Logger::WARNING, str_repeat('a', 100*1024)));
58
59 $expected = array(
60 'X-ChromeLogger-Data' => base64_encode(utf8_encode(json_encode(array(
61 'version' => ChromePHPHandler::VERSION,
62 'columns' => array('label', 'log', 'backtrace', 'type'),
63 'rows' => array(
64 array(
65 'test',
66 'test',
67 'unknown',
68 'log',
69 ),
70 array(
71 'test',
72 str_repeat('a', 150*1024),
73 'unknown',
74 'warn',
75 ),
76 array(
77 'monolog',
78 'Incomplete logs, chrome header size limit reached',
79 'unknown',
80 'warn',
81 ),
82 ),
83 'request_uri' => '',
84 ))))
85 );
86
87 $this->assertEquals($expected, $handler->getHeaders());
88 }
89
90 public function testConcurrentHandlers()
91 {
92 $handler = new TestChromePHPHandler();
93 $handler->setFormatter($this->getIdentityFormatter());
94 $handler->handle($this->getRecord(Logger::DEBUG));
95 $handler->handle($this->getRecord(Logger::WARNING));
96
97 $handler2 = new TestChromePHPHandler();
98 $handler2->setFormatter($this->getIdentityFormatter());
99 $handler2->handle($this->getRecord(Logger::DEBUG));
100 $handler2->handle($this->getRecord(Logger::WARNING));
101
102 $expected = array(
103 'X-ChromeLogger-Data' => base64_encode(utf8_encode(json_encode(array(
104 'version' => ChromePHPHandler::VERSION,
105 'columns' => array('label', 'log', 'backtrace', 'type'),
106 'rows' => array(
107 'test',
108 'test',
109 'test',
110 'test',
111 ),
112 'request_uri' => '',
113 ))))
114 );
115
116 $this->assertEquals($expected, $handler2->getHeaders());
117 }
118}
119
121{
122 protected $headers = array();
123
124 public static function reset()
125 {
126 self::$initialized = false;
127 self::$overflowed = false;
128 self::$sendHeaders = true;
129 self::$json['rows'] = array();
130 }
131
132 protected function sendHeader($header, $content)
133 {
134 $this->headers[$header] = $content;
135 }
136
137 public function getHeaders()
138 {
139 return $this->headers;
140 }
141}
@covers Monolog\Handler\ChromePHPHandler
Handler sending logs to the ChromePHP extension (http://www.chromephp.com/)
const VERSION
Version of the extension.
sendHeader($header, $content)
Send header string to the client.
Monolog log channel.
Definition: Logger.php:28
const WARNING
Exceptional occurrences that are not errors.
Definition: Logger.php:52
const DEBUG
Detailed debug information.
Definition: Logger.php:32
getRecord($level=Logger::WARNING, $message='test', $context=array())
Definition: TestCase.php:19
$header
if((!isset($_SERVER['DOCUMENT_ROOT'])) OR(empty($_SERVER['DOCUMENT_ROOT']))) $_SERVER['DOCUMENT_ROOT']