Updating the various CakeExceptions to take arrays in their constructors. This allows for the existing templates to continue working, as well as generalize the way in which errors are handled. This change also makes the messages coming out of exceptions more readable and removes string hackery.

This commit is contained in:
mark_story 2010-08-29 21:37:25 -04:00
parent 741f2972f9
commit f1164c93d6
22 changed files with 233 additions and 347 deletions

View file

@ -134,7 +134,9 @@ class Dispatcher {
if (!is_object($controller)) {
Router::setRequestInfo($request);
throw new MissingControllerException(Inflector::camelize($request->params['controller']) . 'Controller');
throw new MissingControllerException(array(
'controller' => Inflector::camelize($request->params['controller']) . 'Controller'
));
}
$privateAction = $request->params['action'][0] === '_';
$prefixes = Router::prefixes();
@ -151,12 +153,10 @@ class Dispatcher {
Router::setRequestInfo($request);
if ($privateAction) {
$message = sprintf(
'%s::%s()',
Inflector::camelize($request->params['controller']) . "Controller",
$request->params['action']
);
throw new PrivateActionException($message);
throw new PrivateActionException(array(
'controller' => Inflector::camelize($request->params['controller']) . "Controller",
'action' => $request->params['action']
));
}
return $this->_invoke($controller, $request);
@ -184,12 +184,10 @@ class Dispatcher {
App::import('Controller', 'Scaffold', false);
return new Scaffold($controller, $request);
}
$message = sprintf(
'%s::%s()',
Inflector::camelize($request->params['controller']) . "Controller",
$request->params['action']
);
throw new MissingActionException($message);
throw new MissingActionException(array(
'controller' => Inflector::camelize($request->params['controller']) . "Controller",
'action' => $request->params['action']
));
}
$result =& call_user_func_array(array(&$controller, $request->params['action']), $request->params['pass']);
$response = $controller->getResponse();

View file

@ -54,10 +54,16 @@ class ComponentCollection extends ObjectCollection {
$componentClass = $name . 'Component';
if (!class_exists($componentClass)) {
if (!App::import('Component', $component)) {
throw new MissingComponentFileException(Inflector::underscore($component) . '.php');
throw new MissingComponentFileException(array(
'file' => Inflector::underscore($component) . '.php',
'class' => $componentClass
));
}
if (!class_exists($componentClass)) {
throw new MissingComponentFileException($component);
throw new MissingComponentFileException(array(
'file' => Inflector::underscore($component) . '.php',
'class' => $componentClass
));
}
}
$this->_loaded[$name] = new $componentClass($this, $settings);

View file

@ -414,11 +414,13 @@ class Scaffold {
break;
}
} else {
$message = sprintf('%s::%s()', $this->controller->name . "Controller", $request->action);
throw new MissingActionException($message);
throw new MissingActionException(array(
'controller' => $this->controller->name,
'action' => $request->action
));
}
} else {
throw new MissingDatabaseException($this->ScaffoldModel->useDbConfig);
throw new MissingDatabaseException(array('connection' => $this->ScaffoldModel->useDbConfig));
}
}

View file

@ -40,6 +40,27 @@ class ErrorHandler {
*/
public $controller = null;
/**
* template to render for CakeException
*
* @var string
*/
public $template = '';
/**
* The method corresponding to the Exception this object is for.
*
* @var string
*/
public $method = '';
/**
* The exception being handled.
*
* @var Exception
*/
public $error = null;
/**
* Class constructor.
*
@ -54,27 +75,27 @@ class ErrorHandler {
if (method_exists($this->controller, 'apperror')) {
return $this->controller->appError($exception);
}
$method = Inflector::variable(str_replace('Exception', '', get_class($exception)));
$method = $template = Inflector::variable(str_replace('Exception', '', get_class($exception)));
if (!in_array($method, get_class_methods($this))) {
$method = 'error';
if ($exception instanceof CakeException && !in_array($method, get_class_methods($this))) {
$method = '_cakeError';
}
if ($method !== 'error') {
if (Configure::read('debug') == 0) {
$code = $exception->getCode();
$parentClass = get_parent_class($this);
if ($parentClass != 'ErrorHandler') {
$method = 'error404';
}
$parentMethods = (array)get_class_methods($parentClass);
if (in_array($method, $parentMethods)) {
$method = 'error404';
}
if ($code == 500) {
$method = 'error500';
}
if ($method !== 'error' && Configure::read('debug') == 0) {
$code = $exception->getCode();
$parentClass = get_parent_class($this);
if ($parentClass != 'ErrorHandler') {
$method = 'error404';
}
$parentMethods = (array)get_class_methods($parentClass);
if (in_array($method, $parentMethods)) {
$method = 'error404';
}
if ($code == 500) {
$method = 'error500';
}
}
$this->template = $template;
$this->method = $method;
$this->error = $exception;
}
@ -133,6 +154,24 @@ class ErrorHandler {
$this->error404($error);
}
/**
* Generic handler for the internal framework errors CakePHP can generate.
*
* @param CakeExeption $error
* @return void
*/
protected function _cakeError(CakeException $error) {
$url = Router::normalize($this->controller->request->here);
$code = $error->getCode();
$this->controller->response->statusCode($code);
$this->controller->set(array(
'code' => $code,
'url' => h($url),
));
$this->controller->set($error->getAttributes());
$this->_outputMessage($this->template);
}
/**
* Convenience method to display a 404 page.
*
@ -167,207 +206,11 @@ class ErrorHandler {
));
$this->_outputMessage('error500');
}
/**
* Renders the Missing Controller web page.
*
* @param array $params Parameters for controller
*/
public function missingController($error) {
$controllerName = str_replace('Controller', '', $error->getMessage());
$this->controller->set(array(
'controller' => $error->getMessage(),
'controllerName' => $controllerName
));
$this->_outputMessage('missingController');
}
/**
* Renders the Missing Action web page.
*
* @param array $params Parameters for controller
*/
public function missingAction($error) {
$message = $error->getMessage();
list($controllerName, $action) = explode('::', $message);
$this->controller->set(array(
'controller' => $controllerName,
'action' => $action,
));
$this->_outputMessage('missingAction');
}
/**
* Renders the Private Action web page.
*
* @param array $params Parameters for controller
*/
public function privateAction($error) {
$message = $error->getMessage();
list($controllerName, $action) = explode('::', $message);
$this->controller->set(array(
'controller' => $controllerName,
'action' => $action
));
$this->_outputMessage('privateAction');
}
/**
* Renders the Missing Table web page.
*
* @param array $params Parameters for controller
*/
public function missingTable($error) {
$this->controller->header("HTTP/1.0 500 Internal Server Error");
$this->controller->set(array(
'model' => $error->getModel(),
'table' => $error->getTable(),
));
$this->_outputMessage('missingTable');
}
/**
* Renders the Missing Database web page.
*
* @param array $params Parameters for controller
*/
public function missingDatabase($exception) {
$this->controller->header("HTTP/1.0 500 Internal Server Error");
$this->controller->set(array(
'code' => '500',
'title' => __('Scaffold Missing Database Connection')
));
$this->_outputMessage('missingScaffolddb');
}
/**
* Renders the Missing View web page.
*
* @param array $params Parameters for controller
*/
public function missingView($error) {
$this->controller->set(array(
'file' => $error->getMessage(),
));
$this->_outputMessage('missingView');
}
/**
* Renders the Missing Layout web page.
*
* @param array $params Parameters for controller
*/
public function missingLayout($error) {
$this->controller->layout = 'default';
$this->controller->set(array(
'file' => $error->getMessage(),
));
$this->_outputMessage('missingLayout');
}
/**
* Renders the Database Connection web page.
*
* @param array $params Parameters for controller
*/
public function missingConnection($error) {
$this->controller->header("HTTP/1.0 500 Internal Server Error");
$this->controller->set(array(
'code' => '500',
'model' => $error->getMessage(),
));
$this->_outputMessage('missingConnection');
}
/**
* Renders the Missing Helper file web page.
*
* @param array $params Parameters for controller
*/
public function missingHelperFile($error) {
list($class, $ext) = explode('.', $error->getMessage());
$this->controller->set(array(
'className' => Inflector::camelize($class),
'file' => $error->getMessage()
));
$this->_outputMessage('missingHelperFile');
}
/**
* Renders the Missing Helper class web page.
*
* @param array $params Parameters for controller
*/
public function missingHelperClass($error) {
$class = $error->getMessage();
$file = Inflector::underscore(str_replace('Helper', '', $error->getMessage())) . '.php';
$this->controller->set(array(
'className' => $class,
'file' => $file,
));
$this->_outputMessage('missingHelperClass');
}
/**
* Renders the Missing Behavior file web page.
*
* @param array $params Parameters for controller
*/
public function missingBehaviorFile($error) {
list($class, $ext) = explode('.', $error->getMessage());
$this->controller->set(array(
'className' => Inflector::camelize($class),
'file' => $error->getMessage()
));
$this->_outputMessage('missingBehaviorFile');
}
/**
* Renders the Missing Behavior class web page.
*
* @param array $params Parameters for controller
*/
public function missingBehaviorClass($error) {
$class = $error->getMessage();
$file = Inflector::underscore(str_replace('Behavior', '', $error->getMessage())) . '.php';
$this->controller->set(array(
'className' => $class,
'file' => $file,
));
$this->_outputMessage('missingBehaviorClass');
}
/**
* Renders the Missing Component file web page.
*
* @param array $params Parameters for controller
*/
public function missingComponentFile($error) {
list($class, $ext) = explode('.', $error->getMessage());
$this->controller->set(array(
'className' => Inflector::camelize($class),
'file' => $error->getMessage()
));
$this->_outputMessage('missingComponentFile');
}
/**
* Renders the Missing Component class web page.
*
* @param array $params Parameters for controller
*/
public function missingComponentClass($error) {
$class = $error->getMessage();
$file = Inflector::underscore(str_replace('Component', '', $error->getMessage())) . '.php';
$this->controller->set(array(
'className' => $class,
'file' => $file,
));
$this->_outputMessage('missingComponentClass');
}
/**
* Output message
* Generate the response using the controller object.
*
* @param string $template The template to render.
*/
protected function _outputMessage($template) {
$this->controller->render($template);

View file

@ -18,38 +18,84 @@
* @since CakePHP(tm) v 2.0
* @license MIT License (http://www.opensource.org/licenses/mit-license.php)
*/
class Error404Exception extends RuntimeException {
public function __construct($message, $code = 404) {
if (empty($message)) {
$message = __('Not Found');
}
parent::__construct($message, $code);
}
}
class Error500Exception extends CakeException {
public function __construct($message, $code = 500) {
if (empty($message)) {
$message = __('Internal Server Error');
}
parent::__construct($message, $code);
}
}
/**
* CakeException is used a base class for CakePHP's internal exceptions.
* In general framework errors are interpreted as 500 code errors.
*
* @package cake.libs
*/
class CakeException extends RuntimeException {
public function __construct($message, $code = 500, Exception $previous = null) {
parent::__construct($message, $code, $previous);
class CakeException extends RuntimeException {
protected $_attributes = array();
protected $_messageTemplate = '';
public function __construct($message, $code = 500) {
if (is_array($message)) {
$this->_attributes = $message;
$message = vsprintf(__($this->_messageTemplate), $message);
}
parent::__construct($message, $code);
}
public function getAttributes() {
return $this->_attributes;
}
}
class Error404Exception extends RuntimeException {
public function __construct($message, $code = 404, Exception $previous = null) {
parent::__construct($message, $code, $previous);
}
}
class Error500Exception extends CakeException { }
/*
* Exceptions used by Dispatcher
*/
class MissingControllerException extends Error404Exception { }
class MissingActionException extends Error404Exception { }
class PrivateActionException extends Error404Exception { }
class MissingControllerException extends CakeException {
protected $_messageTemplate = 'Controller class %s could not be found.';
public function __construct($message, $code = 404) {
parent::__construct($message, $code);
}
}
class MissingActionException extends CakeException {
protected $_messageTemplate = 'Action %s::%s() could not be found.';
public function __construct($message, $code = 404) {
parent::__construct($message, $code);
}
}
class PrivateActionException extends CakeException {
protected $_messageTemplate = 'Private Action %s::%s() is not directly accessible.';
public function __construct($message, $code = 404, Exception $previous = null) {
parent::__construct($message, $code, $previous);
}
}
/**
* Exceptions used by the ComponentCollection.
*/
class MissingComponentFileException extends CakeException { }
class MissingComponentClassException extends CakeException { }
class MissingComponentFileException extends CakeException {
protected $_messageTemplate = 'Component File "%s" is missing.';
}
class MissingComponentClassException extends CakeException {
protected $_messageTemplate = 'Component class "%s" is missing.';
}
/**
* Runtime Exceptions for behaviors
@ -60,68 +106,48 @@ class MissingBehaviorClassException extends CakeException { }
/**
* Runtime Exceptions for Views
*/
class MissingViewException extends CakeException { }
class MissingLayoutException extends CakeException { }
class MissingViewException extends CakeException {
protected $_messageTemplate = 'View file "%s" is missing.';
}
class MissingLayoutException extends CakeException {
protected $_messageTemplate = 'Layout file "%s" is missing.';
}
/**
* Exceptions used by the HelperCollection.
*/
class MissingHelperFileException extends CakeException {
protected $_messageTemplate = 'Helper File "%s" is missing.';
}
class MissingHelperClassException extends CakeException {
protected $_messageTemplate = 'Helper class "%s" is missing.';
}
/**
* Runtime Exceptions for ConnectionManager
*/
class MissingDatabaseException extends CakeException {}
class MissingConnectionException extends CakeException {}
class MissingDatabaseException extends CakeException {
protected $_messageTemplate = 'Database connection "%s" could not be found.';
}
class MissingConnectionException extends CakeException {
protected $_messageTemplate = 'Database connection "%s" is missing.';
}
/**
* Exceptions used by the TaskCollection.
*/
class MissingTaskFileException extends CakeException { }
class MissingTaskClassException extends CakeException { }
class MissingTaskFileException extends CakeException {
protected $_messageTemplate = 'Task file "%s" is missing.';
}
class MissingTaskClassException extends CakeException {
protected $_messageTemplate = 'Task class "%s" is missing.';
}
/**
* Exception class to be thrown when a database table is not found in the datasource
*
*/
class MissingTableException extends CakeException {
/**
* The name of the model wanting to load the database table
*
* @var string
*/
protected $model;
/**
* The name of the missing table
*
* @var string
*/
protected $table;
/**
* Exception costructor
*
* @param string $model The name of the model wanting to load the database table
* @param string $table The name of the missing table
* @return void
*/
public function __construct($model, $table) {
$this->model = $model;
$this->table = $table;
$message = sprintf(__('Database table %s for model %s was not found.'), $table, $model);
parent::__construct($message);
}
/**
* Returns the name of the model wanting to load the database table
*
* @return string
*/
public function getModel() {
return $this->model;
}
/**
* Returns the name of the missing table
*
* @return string
*/
public function getTable() {
return $this->table;
}
}
protected $_messageTemplate = 'Database table %s for model %s was not found.';
}

View file

@ -94,10 +94,16 @@ class BehaviorCollection extends ObjectCollection {
$class = $name . 'Behavior';
if (!App::import('Behavior', $behavior)) {
throw new MissingBehaviorFileException(Inflector::underscore($behavior) . '.php');
throw new MissingBehaviorFileException(array(
'file' => Inflector::underscore($behavior) . '.php',
'class' => $class
));
}
if (!class_exists($class)) {
throw new MissingBehaviorClassException(Inflector::underscore($class));
throw new MissingBehaviorClassException(array(
'file' => Inflector::underscore($behavior) . '.php',
'class' => $class
));
}
if (!isset($this->{$name})) {

View file

@ -222,7 +222,7 @@ class ConnectionManager {
$this->_connectionsEnum[$name] = $this->__connectionData($config);
}
} else {
throw new MissingConnectionException('ConnectionManager');
throw new MissingConnectionException(array('class' => 'ConnectionManager'));
}
}

View file

@ -799,7 +799,10 @@ class Model extends Object {
if ($db->isInterfaceSupported('listSources')) {
$sources = $db->listSources();
if (is_array($sources) && !in_array(strtolower($this->tablePrefix . $tableName), array_map('strtolower', $sources))) {
throw new MissingTableException($this->alias, $this->tablePrefix . $tableName);
throw new MissingTableException(array(
'table' => $this->tablePrefix . $tableName,
'class' => $this->alias
));
}
$this->_schema = null;
}
@ -2825,7 +2828,7 @@ class Model extends Object {
}
if (empty($db) || !is_object($db)) {
throw new MissingConnectionException($this->useDbConfig);
throw new MissingConnectionException(array('class' => $this->name));
}
}

View file

@ -24,7 +24,7 @@
</p>
<p class="error">
<strong><?php echo __('Error'); ?>: </strong>
<?php printf(__('Create %1$s%2$s in file: %3$s.'), '<em>' . $controller . '::</em>', '<em>' . $action . '</em>', APP_DIR . DS . 'controllers' . DS . Inflector::underscore($controller) . '.php'); ?>
<?php printf(__('Create %1$s%2$s in file: %3$s.'), '<em>' . $controller . '::</em>', '<em>' . $action . '()</em>', APP_DIR . DS . 'controllers' . DS . Inflector::underscore($controller) . '.php'); ?>
</p>
<pre>
&lt;?php

View file

@ -20,7 +20,7 @@
<h2><?php echo __('Missing Behavior Class'); ?></h2>
<p class="error">
<strong><?php echo __('Error'); ?>: </strong>
<?php printf(__('The behavior class <em>%s</em> can not be found or does not exist.'), $className); ?>
<?php printf(__('The behavior class <em>%s</em> can not be found or does not exist.'), $class); ?>
</p>
<p class="error">
<strong><?php echo __('Error'); ?>: </strong>
@ -28,7 +28,7 @@
</p>
<pre>
&lt;?php
class <?php echo $className;?> extends ModelBehavior {
class <?php echo $class;?> extends ModelBehavior {
}
?&gt;

View file

@ -28,7 +28,7 @@
</p>
<pre>
&lt;?php
class <?php echo $className;?> extends ModelBehavior {
class <?php echo $class;?> extends ModelBehavior {
}
?&gt;

View file

@ -20,15 +20,15 @@
<h2><?php echo __('Missing Component Class'); ?></h2>
<p class="error">
<strong><?php echo __('Error'); ?>: </strong>
<?php printf(__('Component class %1$s was not found.'), '<em>' . $className . '</em>'); ?>
<?php printf(__('Component class %1$s was not found.'), '<em>' . $class . '</em>'); ?>
</p>
<p class="error">
<strong><?php echo __('Error'); ?>: </strong>
<?php printf(__('Create the class %s in file: %s'), '<em>' . $className . '</em>', APP_DIR . DS . 'controllers' . DS . 'components' . DS . $file); ?>
<?php printf(__('Create the class %s in file: %s'), '<em>' . $class . '</em>', APP_DIR . DS . 'controllers' . DS . 'components' . DS . $file); ?>
</p>
<pre>
&lt;?php
class <?php echo $className;?> extends Component {<br />
class <?php echo $class;?> extends Component {<br />
}
?&gt;

View file

@ -24,11 +24,11 @@
</p>
<p class="error">
<strong><?php echo __('Error'); ?>: </strong>
<?php printf(__('Create the class %s in file: %s'), '<em>' . $className . 'Component</em>', APP_DIR . DS . 'controllers' . DS . 'components' . DS . $file); ?>
<?php printf(__('Create the class %s in file: %s'), '<em>' . $class . '</em>', APP_DIR . DS . 'controllers' . DS . 'components' . DS . $file); ?>
</p>
<pre>
&lt;?php
class <?php echo $className;?>Component extends Component {<br />
class <?php echo $class;?> extends Component {<br />
}
?&gt;

View file

@ -20,7 +20,7 @@
<h2><?php echo __('Missing Database Connection'); ?></h2>
<p class="error">
<strong><?php echo __('Error'); ?>: </strong>
<?php printf(__('%s requires a database connection'), $model); ?>
<?php printf(__('%s requires a database connection'), $class); ?>
</p>
<p class="error">
<strong><?php echo __('Error'); ?>: </strong>

View file

@ -20,7 +20,7 @@
<h2><?php echo __('Missing Helper Class'); ?></h2>
<p class="error">
<strong><?php echo __('Error'); ?>: </strong>
<?php printf(__('The helper class <em>%s</em> can not be found or does not exist.'), $className); ?>
<?php printf(__('The helper class <em>%s</em> can not be found or does not exist.'), $class); ?>
</p>
<p class="error">
<strong><?php echo __('Error'); ?>: </strong>
@ -28,7 +28,7 @@
</p>
<pre>
&lt;?php
class <?php echo $className;?> extends AppHelper {
class <?php echo $class;?> extends AppHelper {
}
?&gt;

View file

@ -28,7 +28,7 @@
</p>
<pre>
&lt;?php
class <?php echo $className;?> extends AppHelper {
class <?php echo $class;?> extends AppHelper {
}
?&gt;

View file

@ -20,7 +20,7 @@
<h2><?php echo __('Missing Database Table'); ?></h2>
<p class="error">
<strong><?php echo __('Error'); ?>: </strong>
<?php printf(__('Database table %1$s for model %2$s was not found.'), '<em>' . $table . '</em>', '<em>' . $model . '</em>'); ?>
<?php printf(__('Database table %1$s for model %2$s was not found.'), '<em>' . $table . '</em>', '<em>' . $class . '</em>'); ?>
</p>
<p class="notice">
<strong><?php echo __('Notice'); ?>: </strong>

View file

@ -20,7 +20,7 @@
<h2><?php printf(__('Private Method in %s'), $controller); ?></h2>
<p class="error">
<strong><?php echo __('Error'); ?>: </strong>
<?php printf(__('%s%s cannot be accessed directly.'), '<em>' . $controller . '::</em>', '<em>' . $action . '</em>'); ?>
<?php printf(__('%s%s cannot be accessed directly.'), '<em>' . $controller . '::</em>', '<em>' . $action . '()</em>'); ?>
</p>
<p class="notice">
<strong><?php echo __('Notice'); ?>: </strong>

View file

@ -54,10 +54,16 @@ class HelperCollection extends ObjectCollection {
$helperClass = $name . 'Helper';
if (!class_exists($helperClass)) {
if (!App::import('Helper', $helper)) {
throw new MissingHelperFileException(Inflector::underscore($name) . '.php');
throw new MissingHelperFileException(array(
'class' => $helperClass,
'file' => Inflector::underscore($name) . '.php'
));
}
if (!class_exists($helperClass)) {
throw new MissingHelperClassException($helperClass);
throw new MissingHelperClassException(array(
'class' => $helperClass,
'file' => Inflector::underscore($name) . '.php'
));
}
}
$this->_loaded[$name] = new $helperClass($this->_View, $settings);
@ -73,10 +79,4 @@ class HelperCollection extends ObjectCollection {
return $this->_loaded[$name];
}
}
/**
* Exceptions used by the HelperCollection.
*/
class MissingHelperFileException extends RuntimeException { }
class MissingHelperClassException extends RuntimeException { }
}

View file

@ -791,7 +791,7 @@ class View extends Object {
}
}
}
throw new MissingViewException($defaultPath . $name . $this->ext);
throw new MissingViewException(array('file' => $defaultPath . $name . $this->ext));
}
/**
@ -824,7 +824,7 @@ class View extends Object {
}
}
}
throw new MissingLayoutException($paths[0] . $file . $this->ext);
throw new MissingLayoutException(array('file' => $paths[0] . $file . $this->ext));
}
/**

View file

@ -426,7 +426,7 @@ class ErrorHandlerTest extends CakeTestCase {
function testMissingController() {
$this->skipIf(defined('APP_CONTROLLER_EXISTS'), '%s Need a non-existent AppController');
$exception = new MissingControllerException('PostsController');
$exception = new MissingControllerException(array('controller' => 'PostsController'));
$ErrorHandler = new ErrorHandler($exception);
ob_start();
@ -445,7 +445,7 @@ class ErrorHandlerTest extends CakeTestCase {
* @return void
*/
function testMissingAction() {
$exception = new MissingActionException('PostsController::index()');
$exception = new MissingActionException(array('controller' => 'PostsController', 'action' => 'index'));
$ErrorHandler = new ErrorHandler($exception);
ob_start();
@ -473,7 +473,7 @@ class ErrorHandlerTest extends CakeTestCase {
* @return void
*/
function testPrivateAction() {
$exception = new PrivateActionException('PostsController::_secretSauce()');
$exception = new PrivateActionException(array('controller' => 'PostsController' , 'action' => '_secretSauce'));
$ErrorHandler = new ErrorHandler($exception);
ob_start();
@ -491,14 +491,15 @@ class ErrorHandlerTest extends CakeTestCase {
* @return void
*/
function testMissingTable() {
$exception = new MissingTableException('Article', 'articles');
$exception = new MissingTableException(array('table' => 'articles', 'class' => 'Article'));
$ErrorHandler = new ErrorHandler($exception);
$ErrorHandler->controller->response = $this->getMock('CakeResponse', array('statusCode'));
$ErrorHandler->controller->response->expects($this->once())->method('statusCode')->with(500);
ob_start();
$ErrorHandler->render();
$result = ob_get_clean();
$this->assertPattern('/HTTP\/1\.0 500 Internal Server Error/', $result);
$this->assertPattern('/<h2>Missing Database Table<\/h2>/', $result);
$this->assertPattern('/table <em>articles<\/em> for model <em>Article<\/em>/', $result);
}
@ -510,14 +511,15 @@ class ErrorHandlerTest extends CakeTestCase {
* @return void
*/
function testMissingDatabase() {
$exception = new MissingDatabaseException('default');
$exception = new MissingDatabaseException(array('connection' => 'default'));
$ErrorHandler = new ErrorHandler($exception);
$ErrorHandler->controller->response = $this->getMock('CakeResponse', array('statusCode'));
$ErrorHandler->controller->response->expects($this->once())->method('statusCode')->with(500);
ob_start();
$ErrorHandler->render();
$result = ob_get_clean();
$this->assertPattern('/HTTP\/1\.0 500 Internal Server Error/', $result);
$this->assertPattern('/<h2>Missing Database Connection<\/h2>/', $result);
$this->assertPattern('/Confirm you have created the file/', $result);
}
@ -529,7 +531,7 @@ class ErrorHandlerTest extends CakeTestCase {
* @return void
*/
function testMissingView() {
$exception = new MissingViewException('/posts/about.ctp');
$exception = new MissingViewException(array('file' => '/posts/about.ctp'));
$ErrorHandler = new ErrorHandler($exception);
ob_start();
@ -546,7 +548,7 @@ class ErrorHandlerTest extends CakeTestCase {
* @return void
*/
function testMissingLayout() {
$exception = new MissingLayoutException('layouts/my_layout.ctp');
$exception = new MissingLayoutException(array('file' => 'layouts/my_layout.ctp'));
$ErrorHandler = new ErrorHandler($exception);
ob_start();
@ -564,7 +566,7 @@ class ErrorHandlerTest extends CakeTestCase {
* @return void
*/
function testMissingConnection() {
$exception = new MissingConnectionException('Article');
$exception = new MissingConnectionException(array('class' => 'Article'));
$ErrorHandler = new ErrorHandler($exception);
ob_start();
@ -582,7 +584,7 @@ class ErrorHandlerTest extends CakeTestCase {
* @return void
*/
function testMissingHelperFile() {
$exception = new MissingHelperFileException('my_custom.php');
$exception = new MissingHelperFileException(array('file' => 'my_custom.php', 'class' => 'MyCustomHelper'));
$ErrorHandler = new ErrorHandler($exception);
ob_start();
@ -601,7 +603,7 @@ class ErrorHandlerTest extends CakeTestCase {
* @return void
*/
function testMissingHelperClass() {
$exception = new MissingHelperClassException('MyCustomHelper');
$exception = new MissingHelperClassException(array('file' => 'my_custom.php', 'class' => 'MyCustomHelper'));
$ErrorHandler = new ErrorHandler($exception);
ob_start();
@ -620,7 +622,7 @@ class ErrorHandlerTest extends CakeTestCase {
* @return void
*/
function testMissingBehaviorFile() {
$exception = new MissingBehaviorFileException('my_custom.php');
$exception = new MissingBehaviorFileException(array('file' => 'my_custom.php', 'class' => 'MyCustomBehavior'));
$ErrorHandler = new ErrorHandler($exception);
ob_start();
@ -639,7 +641,7 @@ class ErrorHandlerTest extends CakeTestCase {
* @return void
*/
function testMissingBehaviorClass() {
$exception = new MissingBehaviorClassException('MyCustomBehavior');
$exception = new MissingBehaviorClassException(array('file' => 'my_custom.php', 'class' => 'MyCustomBehavior'));
$ErrorHandler = new ErrorHandler($exception);
ob_start();
@ -657,7 +659,7 @@ class ErrorHandlerTest extends CakeTestCase {
* @return void
*/
function testMissingComponentFile() {
$exception = new MissingComponentFileException('sidebox.php');
$exception = new MissingComponentFileException(array('file' => 'sidebox.php', 'class' => 'SideboxComponent'));
$ErrorHandler = new ErrorHandler($exception);
ob_start();
@ -676,7 +678,7 @@ class ErrorHandlerTest extends CakeTestCase {
* @return void
*/
function testMissingComponentClass() {
$exception = new MissingComponentClassException('SideboxComponent');
$exception = new MissingComponentClassException(array('file' => 'sidebox.php', 'class' => 'SideboxComponent'));
$ErrorHandler = new ErrorHandler($exception);
ob_start();