Create an object and return it using the returnValue() function. For instance:
$myObject = new RandomObject(); $myFactory = $this->getMock('ObjectFactory', array('getRandomObject')); $myFactory->expects($this->any())->method('getRandomObject')->will($this->returnValue($myObject); $this->assertInstanceOf('RandomObject', $myFactory->getRandomObject());
It will pass.
You can also create this object as the layout itself and pass the layout.
source share