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

Model unit testing

You might have already heard that using "fat models, skinny controllers" is a best practice. One of the main benefits of keeping all your business logic inside your model layer is the ability to develop simpler unit tests for your application. Model classes usually depend only on other models, behaviors, or utility classes (libs), allowing you to quickly start coding your unit tests without a ton of mock object configurations.

CakePHP integrates with PHPUnit and provides several tools to help you build your unit tests:

  • Base classes
  • CakeTestCase
  • ControllerTestCase or you can use PHPUnit_Framework_TestCase
  • Fixture integration
  • Test datasource configuration
  • Bake shell to build test files and fixtures

In this recipe, we'll go over most of ...

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