尝试编写 PHP 单元测试时,方法 'setMethods' 已弃用
Method 'setMethods' is deprecated when try to write a PHP Unit Test
我想创建一个模拟来替换资源:
$gateway = $this->getMockBuilder('PaymentGateway')
->setMethods(['transfer'])
->getMock();
我收到这个警告:
Method 'setMethods' is deprecated
如何解决此弃用问题?
从现在开始,我们应该使用 onlyMethods()
(最接近 setMethods()
和 addMethods()
:
$gateway = $this->getMockBuilder('PaymentGateway')
->onlyMethods(['transfer'])
->getMock();
这在 PR (linked from the method PHP doc directly, as seen here).
中有解释
我想创建一个模拟来替换资源:
$gateway = $this->getMockBuilder('PaymentGateway')
->setMethods(['transfer'])
->getMock();
我收到这个警告:
Method 'setMethods' is deprecated
如何解决此弃用问题?
从现在开始,我们应该使用 onlyMethods()
(最接近 setMethods()
和 addMethods()
:
$gateway = $this->getMockBuilder('PaymentGateway')
->onlyMethods(['transfer'])
->getMock();
这在 PR (linked from the method PHP doc directly, as seen here).
中有解释