2012-07-17 86 views
0

我试图在调用一个模拟对象时传递一个对象。像这样:用PHPUnit的模拟对象传递类型对象的参数

public function testGetMedia() 
{ 

$getPrimaryMediaHelper = $this->getMock('GetPrimaryMediaHelper', array('getMedia')); 

$getPrimaryMediaHelper->expects($this->any()) 
    ->method('getMedia') 
    ->with($media1, 'test'); 

} 

第一个参数需要是对象类型,否则测试将失败。我怎样才能将$ media模拟为类型对象?

在此先感谢。

回答

0

我认为下面的代码应该工作

$getPrimaryMediaHelper->expects($this->any()) 
    ->method('getMedia') 
    ->with($this->isType('object')); 
+0

也做到了,谢谢! – brainmonger 2012-07-18 04:03:33