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