Adding tests for Debugger::outputAs()

Adding exceptions for invalid state checking.
This commit is contained in:
Mark Story 2011-08-21 10:19:43 -04:00 committed by mark_story
parent 35fc8352ce
commit daf1251473
2 changed files with 27 additions and 3 deletions

View file

@ -196,6 +196,26 @@ class DebuggerTest extends CakeTestCase {
$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
*

View file

@ -93,7 +93,8 @@ class Debugger {
),
'base' => array(
'traceLine' => '{:reference} - {:path}, line {:line}'
)
),
'log' => array(),
);
/**
@ -558,13 +559,17 @@ class Debugger {
*
* @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 @@ class Debugger {
$format = false;
}
Debugger::outputAs($format);
return $data;
}