phpunit mock - 方法不存在
2022-08-30 22:39:38
我最近在基于CakePhp 3.x的应用程序的IntegmentTestCase中将PHPunit从5.3更新到5.5。我不明白如何更新我的模拟生成脚本。
最初,我像这样创建我的模拟:
$stub = $this->getMock('SomeClass', array('execute'));
$stub->method('execute')
->will($this->returnValue($this->returnUrl));
在更改为 PHPUnit 5.5 后,这给我带来了以下警告:
PHPUnit_Framework_TestCase::getMock() is deprecated,
use PHPUnit_Framework_TestCase::createMock()
or PHPUnit_Framework_TestCase::getMockBuilder() instead
为了修复此警告,我将模拟生成更改为:
$stub = $this->getMockBuilder('SomeClass', array('execute'))->getMock();
$stub->method('execute')
->will($this->returnValue($this->returnUrl));```
现在,我在运行测试时收到以下错误消息:
exception 'PHPUnit_Framework_MockObject_RuntimeException'
with message 'Trying to configure method "execute" which cannot be
configured because it does not exist, has not been specified,
is final, or is static'
有谁知道,如何避免这个错误?谢谢。