Updating more error messages to use exceptions.

This commit is contained in:
mark_story 2010-08-29 01:26:21 -04:00
parent 041aeecce4
commit 7fb62e9b7e
8 changed files with 72 additions and 65 deletions

View file

@ -275,14 +275,11 @@ class ErrorHandler {
*
* @param array $params Parameters for controller
*/
public function missingConnection($params) {
extract($params, EXTR_OVERWRITE);
public function missingConnection($error) {
$this->controller->header("HTTP/1.0 500 Internal Server Error");
$this->controller->set(array(
'code' => '500',
'model' => $className,
'title' => __('Missing Database Connection')
'model' => $error->getMessage(),
));
$this->_outputMessage('missingConnection');
}
@ -292,13 +289,11 @@ class ErrorHandler {
*
* @param array $params Parameters for controller
*/
public function missingHelperFile($params) {
extract($params, EXTR_OVERWRITE);
public function missingHelperFile($error) {
list($class, $ext) = explode('.', $error->getMessage());
$this->controller->set(array(
'helperClass' => Inflector::camelize($helper) . "Helper",
'file' => $file,
'title' => __('Missing Helper File')
'className' => Inflector::camelize($class),
'file' => $error->getMessage()
));
$this->_outputMessage('missingHelperFile');
}
@ -308,13 +303,12 @@ class ErrorHandler {
*
* @param array $params Parameters for controller
*/
public function missingHelperClass($params) {
extract($params, EXTR_OVERWRITE);
public function missingHelperClass($error) {
$class = $error->getMessage();
$file = Inflector::underscore(str_replace('Helper', '', $error->getMessage())) . '.php';
$this->controller->set(array(
'helperClass' => Inflector::camelize($helper) . "Helper",
'className' => $class,
'file' => $file,
'title' => __('Missing Helper Class')
));
$this->_outputMessage('missingHelperClass');
}
@ -324,13 +318,11 @@ class ErrorHandler {
*
* @param array $params Parameters for controller
*/
public function missingBehaviorFile($params) {
extract($params, EXTR_OVERWRITE);
public function missingBehaviorFile($error) {
list($class, $ext) = explode('.', $error->getMessage());
$this->controller->set(array(
'behaviorClass' => Inflector::camelize($behavior) . "Behavior",
'file' => $file,
'title' => __('Missing Behavior File')
'className' => Inflector::camelize($class),
'file' => $error->getMessage()
));
$this->_outputMessage('missingBehaviorFile');
}
@ -340,13 +332,12 @@ class ErrorHandler {
*
* @param array $params Parameters for controller
*/
public function missingBehaviorClass($params) {
extract($params, EXTR_OVERWRITE);
public function missingBehaviorClass($error) {
$class = $error->getMessage();
$file = Inflector::underscore(str_replace('Behavior', '', $error->getMessage())) . '.php';
$this->controller->set(array(
'behaviorClass' => Inflector::camelize($behavior) . "Behavior",
'className' => $class,
'file' => $file,
'title' => __('Missing Behavior Class')
));
$this->_outputMessage('missingBehaviorClass');
}
@ -356,14 +347,11 @@ class ErrorHandler {
*
* @param array $params Parameters for controller
*/
public function missingComponentFile($params) {
extract($params, EXTR_OVERWRITE);
public function missingComponentFile($error) {
list($class, $ext) = explode('.', $error->getMessage());
$this->controller->set(array(
'controller' => $className,
'component' => $component,
'file' => $file,
'title' => __('Missing Component File')
'className' => Inflector::camelize($class),
'file' => $error->getMessage()
));
$this->_outputMessage('missingComponentFile');
}
@ -373,14 +361,12 @@ class ErrorHandler {
*
* @param array $params Parameters for controller
*/
public function missingComponentClass($params) {
extract($params, EXTR_OVERWRITE);
public function missingComponentClass($error) {
$class = $error->getMessage();
$file = Inflector::underscore(str_replace('Component', '', $error->getMessage())) . '.php';
$this->controller->set(array(
'controller' => $className,
'component' => $component,
'className' => $class,
'file' => $file,
'title' => __('Missing Component Class')
));
$this->_outputMessage('missingComponentClass');
}

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

View file

@ -28,7 +28,7 @@
</p>
<pre>
&lt;?php
class <?php echo $behaviorClass;?> extends ModelBehavior {
class <?php echo $className;?> 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 in %2$s was not found.'), '<em>' . $component . 'Component</em>', '<em>' . $controller . 'Controller</em>'); ?>
<?php printf(__('Component class %1$s was not found.'), '<em>' . $className . '</em>'); ?>
</p>
<p class="error">
<strong><?php echo __('Error'); ?>: </strong>
<?php printf(__('Create the class %s in file: %s'), '<em>' . $component . 'Component</em>', APP_DIR . DS . 'controllers' . DS . 'components' . DS . $file); ?>
<?php printf(__('Create the class %s in file: %s'), '<em>' . $className . '</em>', APP_DIR . DS . 'controllers' . DS . 'components' . DS . $file); ?>
</p>
<pre>
&lt;?php
class <?php echo $component;?>Component extends Object {<br />
class <?php echo $className;?> 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>' . $component . 'Component</em>', APP_DIR . DS . 'controllers' . DS . 'components' . DS . $file); ?>
<?php printf(__('Create the class %s in file: %s'), '<em>' . $className . 'Component</em>', APP_DIR . DS . 'controllers' . DS . 'components' . DS . $file); ?>
</p>
<pre>
&lt;?php
class <?php echo $component;?>Component extends Object {<br />
class <?php echo $className;?>Component extends Component {<br />
}
?&gt;

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

View file

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

View file

@ -550,10 +550,13 @@ class ErrorHandlerTest extends CakeTestCase {
* @return void
*/
function testMissingConnection() {
$this->markTestIncomplete('Not implemented now');
$exception = new MissingConnectionException('Article');
$ErrorHandler = new ErrorHandler($exception);
ob_start();
$ErrorHandler = new ErrorHandler('missingConnection', array('className' => 'Article'));
$ErrorHandler->render();
$result = ob_get_clean();
$this->assertPattern('/<h2>Missing Database Connection<\/h2>/', $result);
$this->assertPattern('/Article requires a database connection/', $result);
}
@ -565,10 +568,13 @@ class ErrorHandlerTest extends CakeTestCase {
* @return void
*/
function testMissingHelperFile() {
$this->markTestIncomplete('Not implemented now');
$exception = new MissingHelperFileException('my_custom.php');
$ErrorHandler = new ErrorHandler($exception);
ob_start();
$ErrorHandler = new ErrorHandler('missingHelperFile', array('helper' => 'MyCustom', 'file' => 'my_custom.php'));
$ErrorHandler->render();
$result = ob_get_clean();
$this->assertPattern('/<h2>Missing Helper File<\/h2>/', $result);
$this->assertPattern('/Create the class below in file:/', $result);
$this->assertPattern('/(\/|\\\)my_custom.php/', $result);
@ -581,10 +587,13 @@ class ErrorHandlerTest extends CakeTestCase {
* @return void
*/
function testMissingHelperClass() {
$this->markTestIncomplete('Not implemented now');
$exception = new MissingHelperClassException('MyCustomHelper');
$ErrorHandler = new ErrorHandler($exception);
ob_start();
$ErrorHandler = new ErrorHandler('missingHelperClass', array('helper' => 'MyCustom', 'file' => 'my_custom.php'));
$ErrorHandler->render();
$result = ob_get_clean();
$this->assertPattern('/<h2>Missing Helper Class<\/h2>/', $result);
$this->assertPattern('/The helper class <em>MyCustomHelper<\/em> can not be found or does not exist./', $result);
$this->assertPattern('/(\/|\\\)my_custom.php/', $result);
@ -597,10 +606,13 @@ class ErrorHandlerTest extends CakeTestCase {
* @return void
*/
function testMissingBehaviorFile() {
$this->markTestIncomplete('Not implemented now');
$exception = new MissingBehaviorFileException('my_custom.php');
$ErrorHandler = new ErrorHandler($exception);
ob_start();
$ErrorHandler = new ErrorHandler('missingBehaviorFile', array('behavior' => 'MyCustom', 'file' => 'my_custom.php'));
$ErrorHandler->render();
$result = ob_get_clean();
$this->assertPattern('/<h2>Missing Behavior File<\/h2>/', $result);
$this->assertPattern('/Create the class below in file:/', $result);
$this->assertPattern('/(\/|\\\)my_custom.php/', $result);
@ -613,10 +625,13 @@ class ErrorHandlerTest extends CakeTestCase {
* @return void
*/
function testMissingBehaviorClass() {
$this->markTestIncomplete('Not implemented now');
$exception = new MissingBehaviorClassException('MyCustomBehavior');
$ErrorHandler = new ErrorHandler($exception);
ob_start();
$ErrorHandler = new ErrorHandler('missingBehaviorClass', array('behavior' => 'MyCustom', 'file' => 'my_custom.php'));
$ErrorHandler->render();
$result = ob_get_clean();
$this->assertPattern('/The behavior class <em>MyCustomBehavior<\/em> can not be found or does not exist./', $result);
$this->assertPattern('/(\/|\\\)my_custom.php/', $result);
}
@ -628,10 +643,13 @@ class ErrorHandlerTest extends CakeTestCase {
* @return void
*/
function testMissingComponentFile() {
$this->markTestIncomplete('Not implemented now');
$exception = new MissingComponentFileException('sidebox.php');
$ErrorHandler = new ErrorHandler($exception);
ob_start();
$ErrorHandler = new ErrorHandler('missingComponentFile', array('className' => 'PostsController', 'component' => 'Sidebox', 'file' => 'sidebox.php'));
$ErrorHandler->render();
$result = ob_get_clean();
$this->assertPattern('/<h2>Missing Component File<\/h2>/', $result);
$this->assertPattern('/Create the class <em>SideboxComponent<\/em> in file:/', $result);
$this->assertPattern('/(\/|\\\)sidebox.php/', $result);
@ -644,10 +662,13 @@ class ErrorHandlerTest extends CakeTestCase {
* @return void
*/
function testMissingComponentClass() {
$this->markTestIncomplete('Not implemented now');
$exception = new MissingComponentClassException('SideboxComponent');
$ErrorHandler = new ErrorHandler($exception);
ob_start();
$ErrorHandler = new ErrorHandler('missingComponentClass', array('className' => 'PostsController', 'component' => 'Sidebox', 'file' => 'sidebox.php'));
$ErrorHandler->render();
$result = ob_get_clean();
$this->assertPattern('/<h2>Missing Component Class<\/h2>/', $result);
$this->assertPattern('/Create the class <em>SideboxComponent<\/em> in file:/', $result);
$this->assertPattern('/(\/|\\\)sidebox.php/', $result);