PHPUnit returnCallback example


With the PHPUnit returnCallback() Method, you can dynamically define the return value of mocks.

Example:

public function testCallback()
{
    $globalObject = [];
    $this->mock
        ->expects($this->any())
        ->method('method')
        ->will(
            $this->returnCallback(
                function($param) use ($globalObject) {
                     return globalObject;
                }
            )
        );
}