Book Image

CakePHP 2 Application Cookbook - Third Edition

By : Watts
Book Image

CakePHP 2 Application Cookbook - Third Edition

By: Watts

Overview of this book

If you are a CakePHP developer looking to ease the burden of development, then this book is for you. As a headfirst dive into the framework, this collection of recipes will help you get the most out of CakePHP, and get your applications baked in no time. Even if you're not familiar with the framework, we'll take you from basic CRUD building to useful solutions that will aid in getting the job done quickly and efficiently.
Table of Contents (14 chapters)
13
Index

Creating a fixture

When you're testing your code, it's important to have a static and defined state before you start every test to ensure that every test is isolated and does not impact further testing logic upon execution. Fixtures help you configure the database state before every unit test is executed. These are simply files that describe database tables and contents, and they are located by convention in app/Test/Fixture/.

CakePHP provides both a fixture generation tool using the bake console shell as well as a test database configuration (the test database is used automatically when you run your tests). This way, you can keep your real data and test data in two different databases to avoid any unwanted interactions.

In this recipe, we'll build a fixture using the bake shell for a given model.

Getting ready

We'll first need a table of data to work with. So, create a table named blogs, using the following SQL statement:

CREATE TABLE blogs (
  id INT NOT NULL AUTO_INCREMENT...