Phake - PHP Mocking Framework

   Next

Phake - PHP Mocking Framework

Mike Lively

<m@digitalsandwich.com>

Copyright © 2011 Mike Lively


Table of Contents

Introduction to Phake
1. Getting Started
Support
2. Method Stubbing
Basic Method Stubbing
How Phake::when() Works
Overwriting Existing Stubs
Stubbing Multiple Calls
Stubbing Consecutive Calls
Stubbing Reference Parameters
Partial Mocks
Setting Default Stubs
Stubbing Magic Methods
3. Method Verification
Basic Method Verification
Verifying Method Parameters
Verifying Multiple Invocations
Verifying Calls Happen in a Particular Order
Verifying No Interaction with a Mock so Far
Verifying No Further Interaction with a Mock
Verifying Magic Methods
4. Answers
Throwing Exceptions
Calling the Parent
Capturing a Return Value
Custom Answers
5. Method Parameter Matchers
Using PHPUnit Matchers
Using Hamcrest Matchers
Parameter Capturing
Custom Parameter Matchers
6. Configuration
Setting the Phake Client
Setting the Mock Class Loader

List of Examples

1. CardGame Class
2. CardGame Unit Test
3. CardGame Unit Test with Phake
1.1. Installing Phake Via Pear
2.1. Cool Cart
2.2. ShoppingCartTest
2.3. ShoppingCartTest Output
2.4. Cool Cart
2.5. ShoppingCartTest Output
2.6. ShoppingCartTest
2.7. ShoppingCartTest Output
2.8. ShoppingCartTest
2.9.
2.10.
2.11.
2.12. Stubbing a Reference Parameter
2.13. Conditionally Stubbing a Reference Paramter
2.14. A Test Class
2.15. Using Partial Mocks
2.16. Setting the default stub
2.17. A Magic Class
2.18. Implicitly Stub of __call()
2.19. Explicitly Stubbing __call()
3.1. Multiple Invocations With PHPUnit Mocks - Bad Example
3.2. Multiple Invocations With PHPUnit Mocks - Good Example
3.3. Multiple Invocations With Phake
3.4. Multiple Invocations of the Same Call With Phake
3.5. Verifying Multiple Calls in Order
3.6. A Magic Class
3.7. Implicitly Verify __call()
3.8. Explicitly Verify __call()
4.1. A class with exception logging
4.2. Using thenThrow() to Throw Exceptions
4.3. A Test Class
4.4. Using thenCallParent() to Force a Stub to Call its Parent
5.1. Dealer Strategy Interface
5.2. Example of Default 'Equals' Matching
5.3. Failed Simple Equals Test
5.4. Using PHPUnit Matchers
5.5. Using Hamcrest Matchers
5.6. Card Collection Interface
5.7. Using Argument Captors
5.8. Using Argument Captors With Conditions
5.9. Failed Test of Argument Captor
5.10. Custom Argument Matcher
6.1. Setting the Phake Client
6.2. Setting the Mock Class Loader
   Next
Introduction to Phake
1. Getting Started
Support
2. Method Stubbing
Basic Method Stubbing
How Phake::when() Works
Overwriting Existing Stubs
Stubbing Multiple Calls
Stubbing Consecutive Calls
Stubbing Reference Parameters
Partial Mocks
Setting Default Stubs
Stubbing Magic Methods
3. Method Verification
Basic Method Verification
Verifying Method Parameters
Verifying Multiple Invocations
Verifying Calls Happen in a Particular Order
Verifying No Interaction with a Mock so Far
Verifying No Further Interaction with a Mock
Verifying Magic Methods
4. Answers
Throwing Exceptions
Calling the Parent
Capturing a Return Value
Custom Answers
5. Method Parameter Matchers
Using PHPUnit Matchers
Using Hamcrest Matchers
Parameter Capturing
Custom Parameter Matchers
6. Configuration
Setting the Phake Client
Setting the Mock Class Loader

Copyright © 2011 Mike Lively

This page uses the Perfect 'Left Menu' 2 Column Liquid Layout by Matthew James Taylor.