Last active
July 12, 2023 17:09
-
-
Save lsloan/2d3416e87ff8aea1bdda to your computer and use it in GitHub Desktop.
Mocking a Fluent Interface with PHPUnit
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/* | |
* With PHPUnit one can easily mock a class that implements a fluent interface. | |
* | |
* This will make any method call to your mock object return a reference to itself. | |
*/ | |
$mock = $this->getMock('MyClass'); | |
$mock->expects($this->any()) | |
->method(new PHPUnit_Framework_Constraint_IsAnything()) | |
->will($this->returnSelf()); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment