【发布时间】:2016-03-13 09:25:40
【问题描述】:
我正在测试一个只有 JSON 视图的控制器方法。我的方法按预期运行,但测试方法只返回“MissingViewException”。有没有办法在单元测试中避免这个异常(除了在 View/People/map_leads.ctp 插入一个空文件)?
PeopleController.php
public function mapLeads($territory_id = null) {
$leads = $this->Person->getPeople([
'territory_id' => $territory_id
]);
$this->set('leads', $leads);
}
AppController.php
public $components = ['RequestHandler'];
routes.php
Router::parseExtensions('json');
PeopleControllerTest.php
public function testMapLeads() {
$id = 40;
$result = $this->testAction('/people/mapLeads/' . $id, array('return' => 'vars'));
}
View/People/json/map_leads.ctp 存在并且被 CakePHP 正确使用;只是测试想看View/People/map_leads.ctp。
我查看了CakePHP: calling testAction to a json-returning method causes missing view exception,提醒我将 RequestHandler 添加到 $components。这并不能解决异常。
【问题讨论】:
标签: unit-testing cakephp phpunit cakephp-2.0