Skip to content

Commit

Permalink
Add test for rendering custom exception.
Browse files Browse the repository at this point in the history
When rendering custom exceptions the exception renderer should not
mangle names that do not end in 'Exception'.

Refs #5770
  • Loading branch information
markstory committed Jan 30, 2015
1 parent 9624cc8 commit e905309
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 2 deletions.
4 changes: 2 additions & 2 deletions src/Error/ExceptionRenderer.php
Expand Up @@ -198,11 +198,11 @@ protected function _customMethod($method, $exception)
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;
}
Expand Down
14 changes: 14 additions & 0 deletions tests/TestCase/Error/ExceptionRendererTest.php
Expand Up @@ -617,6 +617,20 @@ public function testCakeExceptionHandling($exception, $patterns, $code)
}
}

/**
* 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.
*
Expand Down

0 comments on commit e905309

Please sign in to comment.