使用phpunit模拟对象,我有一个返回对象的方法。
如何使用expects/method/will方法编写这个方法?
例如:
如何使用expects/method/will方法编写这个方法?
例如:
->will($this->returnValue('Class_Name'));
->will($this->returnValue('Class_Name'));
returnValue()
函数将其返回。例如:$myObject = new RandomObject();
$myFactory = $this->getMock('ObjectFactory', array('getRandomObject'));
$myFactory->expects($this->any())->method('getRandomObject')->will($this->returnValue($myObject);
$this->assertInstanceOf('RandomObject', $myFactory->getRandomObject());
这会过去的。
您还可以将该对象本身创建为模拟对象并传递模拟对象。