【发布时间】:2017-02-16 12:48:24
【问题描述】:
我正在尝试模拟一个 CakePHP 3 组件,该组件检查是否允许用户查看该页面。
我试过了:
$authComponent = $this->getMockBuilder(App\Controller\Component\AuthorizationComponent::class)
->getMock();
$authComponent
->method('isAuthorized')
->willReturn($this->returnValue(true));
但是,在运行测试时,它会说:
Trying to configure method "isAuthorized" which cannot be configured because it does not exist, has not been specified, is final, or is static
很可能我错误地创建了模拟。谁能告诉我如何正确操作?
【问题讨论】:
-
你的组件是什么样的?
标签: unit-testing cakephp mocking phpunit