cakephp-3.x - CakePHP IntegrationTestTrait Post 返回 HTTP 状态 302
问题描述
我正在尝试执行一个简单的测试,将数据发布到 CakePHP 中的表上。我正在使用 IntegrationTestTrait。
我无法成功发布数据。我$this->_response
正在屈服:
object(Cake\Http\Response) {
'status' => (int) 302,
'contentType' => 'text/html',
'headers' => [
'Content-Type' => [
(int) 0 => 'text/html; charset=UTF-8'
],
'Location' => [
(int) 0 => '/'
]
],
'file' => null,
'fileRange' => [],
'cookies' => object(Cake\Http\Cookie\CookieCollection) {
[protected] cookies => []
},
'cacheDirectives' => [],
'body' => ''
}
我的 TestCase 代码如下所示:
public function testAddStudentSuccess() {
$data = [
'last_name' => 'Test',
'first_name' => '05',
'middle_name' => '',
'preferred_name' => '',
'id_number' => '10005',
'contact_id' => '',
'users[0][email]' => 'test_05@email.com'
];
//Test Pre-condition
$query = $this->Students->find('all')->where([
'id_number' => $data['id_number']
]);
$this->post('/students/add', $data);
debug($this->_response);
}
- 我进一步调试,发现测试甚至没有调用控制器的 add() 函数。
我认为这个问题是一个身份验证问题,我尝试按照文档中规定的所有身份验证工作。但是,它没有用。
有谁知道我可以如何进一步调试?任何帮助表示赞赏。谢谢你。
解决方案
推荐阅读
- kafka-consumer-api - kafka消费者中的session.timeout.ms和connections.max.idle.ms有什么区别
- django - Django 似乎不在端口 8000 上运行
- stm32 - CMSIS & STM32,如何开始?
- flutter - 名称 _ApiClient 不是类型,不能在重定向的构造函数中使用
- javascript - 如何在reactjs中使用循环打印图像
- java - JHipster 4.14.5 - 运行项目时发生错误站点
- cypress - 使用@cypress/instrument-cra 构建的 React-scripts 不会触发 localhost 的等待
- kotlin - build.gradle 中 Kotlin 的不完整依赖项
- javascript - 使元素下降到底部位置
- c# - C# 为特定字符后的第二个值排序字符串