Skip to content

Commit

Permalink
Added return before redirects
Browse files Browse the repository at this point in the history
As recommended by the Cookbook:
http://book.cakephp.org/2.0/en/development/testing.html#testing-controllers

> When testing actions that contain redirect() and other code following the redirect it is generally a good idea to return when redirecting. The reason for this, is that redirect() is mocked in testing, and does not exit like normal. And instead of your code exiting, it will continue to run code following the redirect.
  • Loading branch information
ravage84 committed Jul 28, 2013
1 parent 8a81903 commit 4a37ad5
Showing 1 changed file with 4 additions and 4 deletions.
Expand Up @@ -56,7 +56,7 @@
if ($this-><?php echo $currentModelName; ?>->save($this->request->data)) {
<?php if ($wannaUseSession): ?>
$this->Session->setFlash(__('The <?php echo strtolower($singularHumanName); ?> has been saved'));
$this->redirect(array('action' => 'index'));
return $this->redirect(array('action' => 'index'));
<?php else: ?>
$this->flash(__('<?php echo ucfirst(strtolower($currentModelName)); ?> saved.'), array('action' => 'index'));
<?php endif; ?>
Expand Down Expand Up @@ -99,7 +99,7 @@
if ($this-><?php echo $currentModelName; ?>->save($this->request->data)) {
<?php if ($wannaUseSession): ?>
$this->Session->setFlash(__('The <?php echo strtolower($singularHumanName); ?> has been saved'));
$this->redirect(array('action' => 'index'));
return $this->redirect(array('action' => 'index'));
<?php else: ?>
$this->flash(__('The <?php echo strtolower($singularHumanName); ?> has been saved.'), array('action' => 'index'));
<?php endif; ?>
Expand Down Expand Up @@ -145,7 +145,7 @@
if ($this-><?php echo $currentModelName; ?>->delete()) {
<?php if ($wannaUseSession): ?>
$this->Session->setFlash(__('<?php echo ucfirst(strtolower($singularHumanName)); ?> deleted'));
$this->redirect(array('action' => 'index'));
return $this->redirect(array('action' => 'index'));
<?php else: ?>
$this->flash(__('<?php echo ucfirst(strtolower($singularHumanName)); ?> deleted'), array('action' => 'index'));
<?php endif; ?>
Expand All @@ -155,5 +155,5 @@
<?php else: ?>
$this->flash(__('<?php echo ucfirst(strtolower($singularHumanName)); ?> was not deleted'), array('action' => 'index'));
<?php endif; ?>
$this->redirect(array('action' => 'index'));
return $this->redirect(array('action' => 'index'));
}

0 comments on commit 4a37ad5

Please sign in to comment.