Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
Split Debugger::outputAs() into getter/setter
  • Loading branch information
Michael Hoffmann committed Apr 20, 2017
1 parent 25e5dc5 commit 04bd13b
Show file tree
Hide file tree
Showing 2 changed files with 54 additions and 0 deletions.
32 changes: 32 additions & 0 deletions src/Error/Debugger.php
Expand Up @@ -650,9 +650,41 @@ protected static function _object($var, $depth, $indent)
return $out;
}

/**
* Get the output format for Debugger error rendering.
*
* @return string Returns the current format when getting.
*/
public static function getOutputAs()
{
$self = Debugger::getInstance();

return $self->_outputFormat;
}

/**
* Set the output format for Debugger error rendering.
*
* @param string $format The format you want errors to be output as.
* @return null
* @throws \InvalidArgumentException When choosing a format that doesn't exist.
*/
public static function setOutputAs($format)
{
$self = Debugger::getInstance();

if (!isset($self->_templates[$format])) {
throw new InvalidArgumentException('Invalid Debugger output format.');
}
$self->_outputFormat = $format;

return null;
}

/**
* Get/Set the output format for Debugger error rendering.
*
* @deprecated 3.5.0 Use getOutputAs()/setOutputAs() instead.
* @param string|null $format The format you want errors to be output as.
* Leave null to get the current format.
* @return string|null Returns null when setting. Returns the current format when getting.
Expand Down
22 changes: 22 additions & 0 deletions tests/TestCase/Error/DebuggerTest.php
Expand Up @@ -153,6 +153,28 @@ public function testOutputAsException()
Debugger::outputAs('Invalid junk');
}

/**
* Test that getOutputAs/setOutputAs works.
*
* @return void
*/
public function testGetSetOutputAs()
{
Debugger::setOutputAs('html');
$this->assertEquals('html', Debugger::getOutputAs());
}

/**
* Test that choosing a non-existent format causes an exception
*
* @expectedException \InvalidArgumentException
* @return void
*/
public function testSetOutputAsException()
{
Debugger::setOutputAs('Invalid junk');
}

/**
* Test outputError with description encoding
*
Expand Down

0 comments on commit 04bd13b

Please sign in to comment.