@@ -146,14 +146,83 @@ public function testOutputAsException()
146
146
Debugger::outputAs ('Invalid junk ' );
147
147
}
148
148
149
+ /**
150
+ * Tests that changes in output formats using Debugger::output() change the templates used.
151
+ *
152
+ * @return void
153
+ */
154
+ public function testAddFormat ()
155
+ {
156
+ Debugger::addFormat ('js ' , array (
157
+ 'traceLine ' => '{:reference} - <a href="txmt://open?url=file://{:file} ' .
158
+ '&line={:line}">{:path}</a>, line {:line} '
159
+ ));
160
+ Debugger::outputAs ('js ' );
161
+
162
+ $ result = Debugger::trace ();
163
+ $ this ->assertRegExp ('/ ' . preg_quote ('txmt://open?url=file:// ' , '/ ' ) . '(\/|[A-Z]: \\\\) ' . '/ ' , $ result );
164
+
165
+ Debugger::addFormat ('xml ' , array (
166
+ 'error ' => '<error><code>{:code}</code><file>{:file}</file><line>{:line}</line> ' .
167
+ '{:description}</error> ' ,
168
+ ));
169
+ Debugger::outputAs ('xml ' );
170
+
171
+ ob_start ();
172
+ $ debugger = Debugger::getInstance ();
173
+ $ debugger ->outputError ([
174
+ 'level ' => E_NOTICE ,
175
+ 'code ' => E_NOTICE ,
176
+ 'file ' => __FILE__ ,
177
+ 'line ' => __LINE__ ,
178
+ 'description ' => 'Undefined variable: foo ' ,
179
+ ]);
180
+ $ result = ob_get_clean ();
181
+
182
+ $ expected = array (
183
+ '<error ' ,
184
+ '<code ' , '8 ' , '/code ' ,
185
+ '<file ' , 'preg:/[^<]+/ ' , '/file ' ,
186
+ '<line ' , '' . ((int )__LINE__ - 9 ), '/line ' ,
187
+ 'preg:/Undefined variable:\s+foo/ ' ,
188
+ '/error '
189
+ );
190
+ $ this ->assertHtml ($ expected , $ result , true );
191
+ }
192
+
193
+ /**
194
+ * Test adding a format that is handled by a callback.
195
+ *
196
+ * @return void
197
+ */
198
+ public function testAddFormatCallback ()
199
+ {
200
+ Debugger::addFormat ('callback ' , array ('callback ' => array ($ this , 'customFormat ' )));
201
+ Debugger::outputAs ('callback ' );
202
+
203
+ ob_start ();
204
+ $ debugger = Debugger::getInstance ();
205
+ $ debugger ->outputError ([
206
+ 'error ' => 'Notice ' ,
207
+ 'code ' => E_NOTICE ,
208
+ 'level ' => E_NOTICE ,
209
+ 'description ' => 'Undefined variable $foo ' ,
210
+ 'file ' => __FILE__ ,
211
+ 'line ' => __LINE__ ,
212
+ ]);
213
+ $ result = ob_get_clean ();
214
+ $ this ->assertContains ('Notice: I eated an error ' , $ result );
215
+ $ this ->assertContains ('DebuggerTest.php ' , $ result );
216
+ }
217
+
149
218
/**
150
219
* Test method for testing addFormat with callbacks.
151
220
*
152
221
* @return void
153
222
*/
154
223
public function customFormat ($ error , $ strings )
155
224
{
156
- return $ error ['error ' ] . ': I eated an error ' . $ error ['file ' ];
225
+ echo $ error ['error ' ] . ': I eated an error ' . $ error ['file ' ];
157
226
}
158
227
159
228
/**
0 commit comments