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

Creating fixtures and testing model methods

In this recipe, we will learn how to create test data that we can use to test our application without altering real data, and how to create our own unit tests to cover model functionality.

Getting ready

To go through this recipe, we need a basic application skeleton to work with and have the SimpleTest library installed. Go through the entire recipe, Setting up the test framework.

How to do it...

  1. Create a file named article_fixture.php and place it in your app/tests/fixtures folder with the following contents:
    <?php class ArticleFixture extends CakeTestFixture { public $import = 'Article'; public $records = array( array( 'id' => 1, 'title' => 'Article 1', 'body' => 'Body for Article 1' ), array( 'id' => ...

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