Skip to content

Commit

Permalink
Adding tests for Debugger::outputAs()
Browse files Browse the repository at this point in the history
Adding exceptions for invalid state checking.
  • Loading branch information
markstory committed Aug 23, 2011
1 parent 35fc835 commit daf1251
Show file tree
Hide file tree
Showing 2 changed files with 27 additions and 3 deletions.
20 changes: 20 additions & 0 deletions lib/Cake/Test/Case/Utility/DebuggerTest.php
Expand Up @@ -196,6 +196,26 @@ public function testChangeOutputFormats() {
$this->assertTags($result, $data, true);
}

/**
* 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
*
Expand Down
10 changes: 7 additions & 3 deletions lib/Cake/Utility/Debugger.php
Expand Up @@ -93,7 +93,8 @@ class Debugger {
),
'base' => array(
'traceLine' => '{:reference} - {:path}, line {:line}'
)
),
'log' => array(),
);

/**
Expand Down Expand Up @@ -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;
}

Expand Down Expand Up @@ -641,7 +646,6 @@ public function output($format = null, $strings = array()) {
$format = false;
}
Debugger::outputAs($format);

return $data;
}

Expand Down

0 comments on commit daf1251

Please sign in to comment.