Skip to content

Commit daf1251

Browse files
committed
Adding tests for Debugger::outputAs()
Adding exceptions for invalid state checking.
1 parent 35fc835 commit daf1251

File tree

2 files changed

+27
-3
lines changed

2 files changed

+27
-3
lines changed

lib/Cake/Test/Case/Utility/DebuggerTest.php

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -196,6 +196,26 @@ public function testChangeOutputFormats() {
196196
$this->assertTags($result, $data, true);
197197
}
198198

199+
/**
200+
* Test that outputAs works.
201+
*
202+
* @return void
203+
*/
204+
public function testOutputAs() {
205+
Debugger::outputAs('html');
206+
$this->assertEquals('html', Debugger::outputAs());
207+
}
208+
209+
/**
210+
* Test that choosing a non-existant format causes an exception
211+
*
212+
* @expectedException CakeException
213+
* @return void
214+
*/
215+
public function testOutputAsException() {
216+
Debugger::outputAs('Invalid junk');
217+
}
218+
199219
/**
200220
* testTrimPath method
201221
*

lib/Cake/Utility/Debugger.php

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -93,7 +93,8 @@ class Debugger {
9393
),
9494
'base' => array(
9595
'traceLine' => '{:reference} - {:path}, line {:line}'
96-
)
96+
),
97+
'log' => array(),
9798
);
9899

99100
/**
@@ -558,13 +559,17 @@ protected static function _object($var) {
558559
*
559560
* @param string $format The format you want errors to be output as.
560561
* Leave null to get the current format.
561-
* @return void
562+
* @return mixed Returns null when setting. Returns the current format when getting.
563+
* @throws CakeException when choosing a format that doesn't exist.
562564
*/
563565
public static function outputAs($format = null) {
564566
$self = Debugger::getInstance();
565567
if ($format === null) {
566568
return $self->_outputFormat;
567569
}
570+
if ($format !== false && !isset($self->_templates[$format])) {
571+
throw new CakeException(__d('cake_dev', 'Invalid Debugger output format.'));
572+
}
568573
$self->_outputFormat = $format;
569574
}
570575

@@ -641,7 +646,6 @@ public function output($format = null, $strings = array()) {
641646
$format = false;
642647
}
643648
Debugger::outputAs($format);
644-
645649
return $data;
646650
}
647651

0 commit comments

Comments
 (0)