Browse Source

Add test for rendering custom exception.

When rendering custom exceptions the exception renderer should not
mangle names that do not end in 'Exception'.

Refs #5770
Mark Story 11 years ago
parent
commit
e905309fcf
2 changed files with 16 additions and 2 deletions
  1. 2 2
      src/Error/ExceptionRenderer.php
  2. 14 0
      tests/TestCase/Error/ExceptionRendererTest.php

+ 2 - 2
src/Error/ExceptionRenderer.php

@@ -198,11 +198,11 @@ class ExceptionRenderer
     protected function _method(\Exception $exception)
     {
         list(, $baseClass) = namespaceSplit(get_class($exception));
-        
+
         if (substr($baseClass, -9) === 'Exception') {
             $baseClass = substr($baseClass, 0, -9);
         }
-        
+
         $method = Inflector::variable($baseClass) ?: 'error500';
         return $this->method = $method;
     }

+ 14 - 0
tests/TestCase/Error/ExceptionRendererTest.php

@@ -618,6 +618,20 @@ class ExceptionRendererTest extends TestCase
     }
 
     /**
+     * Test that class names not ending in Exception are not mangled.
+     *
+     * @return void
+     */
+    public function testExceptionNameMangling()
+    {
+        $exception = $this->getMock('Exception', [], ['Bad things', 404], 'MissingWidgetThing');
+        $exceptionRenderer = new MyCustomExceptionRenderer($exception);
+
+        $result = $exceptionRenderer->render()->body();
+        $this->assertContains('widget thing is missing', $result);
+    }
+
+    /**
      * Test exceptions being raised when helpers are missing.
      *
      * @return void