O'Reilly logo

CakePHP 2 Application Cookbook by Jorge González, James Watts

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 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 ...

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