【发布时间】:2021-10-27 04:59:55
【问题描述】:
我正在尝试模拟 Throwable 接口,但 MockBuilder 没有看到 getPrevious() 方法。
$throwableMock = $this->getMockBuilder(\Throwable::class)
->disableOriginalConstructor()
->getMock();
$throwableMock->method('getPrevious')
->willReturn($domainExceptionMock);
我收到此错误:
Trying to configure method "getPrevious" which cannot be configured because it does not exist, has not been specified, is final, or is static
如果我将 addMethods 添加到模拟生成器,如下所示:
$throwableMock = $this->getMockBuilder(\Throwable::class)
->addMethods(['getPrevious'])
->disableOriginalConstructor()
->getMock();
我收到以下错误:
Trying to set mock method "getPrevious" with addMethods(), but it exists in class "Throwable". Use onlyMethods() for methods that exist in the class
我做错了什么?
【问题讨论】: