使用PHPUnit的模拟对象传递类型对象的参数

时间:2012-07-17 04:44:32

标签: php phpunit

我正在尝试在调用模拟对象时传递一个对象。像这样:

public function testGetMedia()
{

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

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

}

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

提前致谢。

1 个答案:

答案 0 :(得分:0)

我认为以下代码应该有效

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