Skip to content
Permalink
Browse files

Making subclassing of ErrorHandler much easier.

Test cases added.
  • Loading branch information...
markstory committed Oct 9, 2009
1 parent 955bd33 commit d59a2c8de159b70758f191504e2bcb8472762ecc
Showing with 62 additions and 2 deletions.
  1. +5 −2 cake/libs/error.php
  2. +57 −0 cake/tests/cases/libs/error.test.php
@@ -110,8 +110,11 @@ function __construct($method, $messages) {
}
if ($method !== 'error') {
if (Configure::read() == 0) {
$method = 'error404';
if (Configure::read('debug') == 0) {
$parentMethods = get_class_methods(get_parent_class($this));
if (in_array($method, $parentMethods)) {
$method = 'error404';
}
if (isset($code) && $code == 500) {
$method = 'error500';
}
@@ -207,6 +207,34 @@ class BlueberryController extends AppController {
var $components = array('Auth');
}
/**
* MyCustomErrorHandler class
*
* @package cake
* @subpackage cake.tests.cases.libs
*/
class MyCustomErrorHandler extends ErrorHandler {
/**
* custom error message type.
*
* @return void
**/
function missingWidgetThing() {
echo 'widget thing is missing';
}
/**
* stop method
*
* @access public
* @return void
*/
function _stop() {
return;
}
}
/**
* TestErrorHandler class
*
@@ -244,6 +272,35 @@ function skip() {
$this->skipIf(PHP_SAPI === 'cli', '%s Cannot be run from console');
}
/**
* test that methods declared in an ErrorHandler subclass are not converted
* into error404 when debug == 0
*
* @return void
**/
function testSubclassMethodsNotBeingConvertedToError() {
$back = Configure::read('debug');
Configure::write('debug', 2);
ob_start();
$ErrorHandler = new MyCustomErrorHandler('missingWidgetThing', array('message' => 'doh!'));
$result = ob_get_clean();
$this->assertEqual($result, 'widget thing is missing');
Configure::write('debug', 0);
ob_start();
$ErrorHandler = new MyCustomErrorHandler('missingWidgetThing', array('message' => 'doh!'));
$result = ob_get_clean();
$this->assertEqual($result, 'widget thing is missing', 'Method declared in subclass converted to error404. %s');
Configure::write('debug', 0);
ob_start();
$ErrorHandler = new MyCustomErrorHandler('missingController', array('message' => 'Page not found'));
$result = ob_get_clean();
$this->assertPattern('/Not Found/', $result, 'Method declared in error handler not converted to error404. %s');
Configure::write('debug', $back);
}
/**
* testError method
*

0 comments on commit d59a2c8

Please sign in to comment.
You can’t perform that action at this time.