我想创建一个模拟来替换资源:
$gateway = $this->getMockBuilder('PaymentGateway') ->setMethods(['transfer']) ->getMock();
我收到此警告:
方法'setMethods'已过时
我该如何解决此弃用问题?
从现在开始,我们应该使用其中任何一种onlyMethods()(这与setMethods()和最接近addMethods():
onlyMethods()
setMethods()
addMethods()
$gateway = $this->getMockBuilder('PaymentGateway') ->onlyMethods(['transfer']) ->getMock();
PR中对此进行了解释(直接从方法PHP doc链接,如此处所示)。
谢谢您的回答:我用onlyMethods替换了setMethods,并且收到有关Class PaymentGateway不存在的警告!
那是一个不同的问题。与原始问题无关。您可能应该传递完全合格的类名称。或者
PaymentGateway::class
当我使用addMethods时,我的测试还可以,并且没有收到警告,我了解我将修改自己的代码以与onlyMethods一起使用。谢谢