我正在尝试模拟一个链式(嵌套)方法来返回所需的值,这是代码:
public function __construct($db)
{
$this->db = $db;
}
public function getResults()
{
return $this->db->getFinder()->find($this->DBTable);
}
我尝试使用这个模拟,但它并不起作用:
$dbMock = $this->createMock(DB::class);
$dbMock = $dbMock
->expects(self::any())
->method('getFinder')
->method('find')
->with('questions')
->will($this->returnValue('7'));
有没有解决这个问题的方案?
谢谢。