Browse Source

Split Debugger::outputAs() into getter/setter

Michael Hoffmann 9 years ago
parent
commit
04bd13bcf2
2 changed files with 54 additions and 0 deletions
  1. 32 0
      src/Error/Debugger.php
  2. 22 0
      tests/TestCase/Error/DebuggerTest.php

+ 32 - 0
src/Error/Debugger.php

@@ -651,8 +651,40 @@ class Debugger
     }
 
     /**
+     * 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.

+ 22 - 0
tests/TestCase/Error/DebuggerTest.php

@@ -154,6 +154,28 @@ class DebuggerTest extends TestCase
     }
 
     /**
+     * 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
      *
      * @return void