【问题标题】:'Cake\View\Exception\MissingTemplateException' with phpunit'Cake\View\Exception\MissingTemplateException' 与 phpunit
【发布时间】:2024-05-03 11:30:02
【问题描述】:

当我使用 Postman 等应用程序测试我的 REST API 时,它运行良好。

但是当我运行 phpunit 时出现错误

exception 'Cake\View\Exception\MissingTemplateException' with message 'Template file "Addresses/json/add.ctp" is missing.'

在 AppController 中

$this->RequestHandler->renderAs($this, 'json');

路线

$routes->extensions(['json']);
$routes->resources('Addresses');

ControllerTest 简单

$this->post('/addresses/');

因为它是 100% API,所以我不需要任何视图。

【问题讨论】:

  • 你需要显示你的控制器代码。

标签: cakephp cakephp-3.0


【解决方案1】:

仅供参考,我忘了添加序列化

$this->set('_serialize', ['data' => 'data']);

【讨论】: