Permalink
Browse files

Adding tests for Debugger::outputAs()

Adding exceptions for invalid state checking.
  • Loading branch information...
1 parent 35fc835 commit daf1251473b33199ab1dc26932f8630f6c25f9ab @markstory markstory committed with markstory Aug 21, 2011
Showing with 27 additions and 3 deletions.
  1. +20 −0 lib/Cake/Test/Case/Utility/DebuggerTest.php
  2. +7 −3 lib/Cake/Utility/Debugger.php
@@ -197,6 +197,26 @@ public function testChangeOutputFormats() {
}
/**
+ * Test that outputAs works.
+ *
+ * @return void
+ */
+ public function testOutputAs() {
+ Debugger::outputAs('html');
+ $this->assertEquals('html', Debugger::outputAs());
+ }
+
+/**
+ * Test that choosing a non-existant format causes an exception
+ *
+ * @expectedException CakeException
+ * @return void
+ */
+ public function testOutputAsException() {
+ Debugger::outputAs('Invalid junk');
+ }
+
+/**
* testTrimPath method
*
* @access public
@@ -93,7 +93,8 @@ class Debugger {
),
'base' => array(
'traceLine' => '{:reference} - {:path}, line {:line}'
- )
+ ),
+ 'log' => array(),
);
/**
@@ -558,13 +559,17 @@ protected static function _object($var) {
*
* @param string $format The format you want errors to be output as.
* Leave null to get the current format.
- * @return void
+ * @return mixed Returns null when setting. Returns the current format when getting.
+ * @throws CakeException when choosing a format that doesn't exist.
*/
public static function outputAs($format = null) {
$self = Debugger::getInstance();
if ($format === null) {
return $self->_outputFormat;
}
+ if ($format !== false && !isset($self->_templates[$format])) {
+ throw new CakeException(__d('cake_dev', 'Invalid Debugger output format.'));
+ }
$self->_outputFormat = $format;
}
@@ -641,7 +646,6 @@ public function output($format = null, $strings = array()) {
$format = false;
}
Debugger::outputAs($format);
-
return $data;
}

0 comments on commit daf1251

Please sign in to comment.