O'Reilly logo

Learn CakePHP: With Unit Testing, Second Edition by Rādhārādhya Dāsa

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

© Sándor Gömöri 2016

Rādhārādhya Dāsa, Learn CakePHP, 10.1007/978-1-4842-1212-7_10

10. Mocks

Rādhārādhya Dāsa

(1)Somogyvamos, Hungary

A337704_2_En_10_Figa_HTML.jpg

Little pig, little pig, let me in

We often require mocked components, models, objects, or even core PHP functions. You can create mocks in any of the test functions or, if you require mock objects in all of the test functions, in the setUp() method.

Mocks ensure that your tests run faster, without actually having all the required objects.

Mocking Sessions

The IntegrationTestCase class provides a few helper methods to mock request objects, including sessions, cookies, headers, etc.

Let’s see an example for session variables. ...

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