mirror of
https://github.com/kamilwylegala/cakephp2-php8.git
synced 2025-01-19 02:56:15 +00:00
Making subclassing of ErrorHandler much easier.
Test cases added.
This commit is contained in:
parent
955bd338e7
commit
d59a2c8de1
2 changed files with 62 additions and 2 deletions
|
@ -110,8 +110,11 @@ class ErrorHandler extends Object {
|
|||
}
|
||||
|
||||
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 @@ class ErrorHandlerTest extends CakeTestCase {
|
|||
$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
|
||||
*
|
||||
|
|
Loading…
Add table
Reference in a new issue