Skip to content

Instantly share code, notes, and snippets.

@lsloan
Last active July 12, 2023 17:09
Show Gist options
  • Save lsloan/2d3416e87ff8aea1bdda to your computer and use it in GitHub Desktop.
Save lsloan/2d3416e87ff8aea1bdda to your computer and use it in GitHub Desktop.
Mocking a Fluent Interface with PHPUnit
/*
* 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