O'Reilly logo

CakePHP 1.3 Application Development Cookbook by Mariano Iglesias

Stay ahead with the world's most comprehensive technology and business learning platform.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, tutorials, and more.

Start Free Trial

No credit card required

Using mocks to test controllers

In this recipe we will learn how to extend what we have covered in the previous recipe by using mocks, an indispensable tool for building powerful test cases.

Getting ready

To go through this recipe, we need unit tests already in place. Go through the previous recipe.

How to do it...

  1. Edit your app/tests/cases/controllers/articles_controller.test.php file and place the following code at the beginning, right before the declaration of the class ArticlesControllerTestCase:
    App::import('Controller', 'Articles'); class TestArticlesController extends ArticlesController { public $name = 'Articles'; public $testRedirect = false; public function __construct() { parent::__construct(); Configure::write('controllers.'.$this->name, ...

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, interactive tutorials, and more.

Start Free Trial

No credit card required