【发布时间】:2017-01-28 19:03:52
【问题描述】:
我最近在基于 CakePhp 3.x 的应用程序的 IntegrationTestCase 中将 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'
任何人都知道,如何避免这个错误?谢谢。
【问题讨论】:
-
可以发一下
execute方法的代码吗?
标签: php unit-testing cakephp phpunit cakephp-3.0