Book Image

CakePHP 2 Application Cookbook

By : James Watts, Cake Software Foundation, Inc.
Book Image

CakePHP 2 Application Cookbook

By: James Watts, Cake Software Foundation, Inc.

Overview of this book

Table of Contents (20 chapters)
CakePHP 2 Application Cookbook
Credits
Foreword
About the Authors
About the Reviewer
www.PacktPub.com
Preface
Index

Stub method configuration


Mock objects have the ability to customize the return values for specific methods. Instead of returning null by default, you can configure the mock object methods to return a specific value, something that you'll find useful in your unit tests to check for specific edge cases when calling other objects (dependencies).

These also have the ability to define expectations on the methods called, to check if the right methods were called with the expected parameters or if they were called in the right order, and so on. This way, we don't need to actually test an external dependent class, but we can define a contract between the tested object and the dependencies.

Mock object methods can be configured to act as stub methods:

Stub methods will return null by default, but you can configure the return value using the will() method. They are defined in the setMethods() array, or you don't call setMethods() or call it using array().

Getting ready

In this recipe, we'll be using the...