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

Get Learn CakePHP: With Unit Testing, Second Edition now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.