Skip to content
Permalink
Browse files

Updating more error messages to use exceptions.

  • Loading branch information...
markstory committed Aug 29, 2010
1 parent 041aeec commit 7fb62e9b7e77b6b7a5d7832a900d6c5ef9cbfb0a
@@ -275,14 +275,11 @@ public function missingLayout($error) {
*
* @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 @@ public function missingConnection($params) {
*
* @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 @@ public function missingHelperFile($params) {
*
* @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 @@ public function missingHelperClass($params) {
*
* @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 @@ public function missingBehaviorFile($params) {
*
* @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 @@ public function missingBehaviorClass($params) {
*
* @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 @@ public function missingComponentFile($params) {
*
* @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');
}
@@ -20,15 +20,15 @@
<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>
<?php printf(__('Create the class below in file: %s'), APP_DIR . DS . 'models' . DS . 'behaviors' . DS . $file); ?>
</p>
<pre>
&lt;?php
class <?php echo $behaviorClass;?> extends ModelBehavior {
class <?php echo $className;?> extends ModelBehavior {

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

}
?&gt;
@@ -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;
@@ -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;
@@ -20,15 +20,15 @@
<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>
<?php printf(__('Create the class below in file: %s'), APP_DIR . DS . 'views' . DS . 'helpers' . DS . $file); ?>
</p>
<pre>
&lt;?php
class <?php echo $helperClass;?> extends AppHelper {
class <?php echo $className;?> extends AppHelper {

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

}
?&gt;
@@ -550,10 +550,13 @@ function testMissingLayout() {
* @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 @@ function testMissingConnection() {
* @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 @@ function testMissingHelperFile() {
* @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 @@ function testMissingHelperClass() {
* @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 @@ function testMissingBehaviorFile() {
* @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 @@ function testMissingBehaviorClass() {
* @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 @@ function testMissingComponentFile() {
* @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);

0 comments on commit 7fb62e9

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