我想测试我的宁静控制器消费JSON数据。问题是我无法正确发送数据。CakePHP3集成测试和JSON数据
这是我尝试发送数据:
$this->configRequest([
'headers' => [
'Accept' => 'application/json',
'Content-Type' => 'application/json'
],
]);
$this->post('/api/users', "{'username':'Iason','password':'test'}");
debug($this->_response->body());
在我的控制,我检查数据:
if (empty($this->request->data)) {
throw new BadRequestException("No data");
}
的检查失败,我回来了错误。
如果我使用邮差测试我的API,一切工作正常。如果我尝试以数组的形式发送数据(手册中显示http://book.cakephp.org/3.0/en/development/testing.html#controller-integration-testing),则控制器中也没有任何请求数据。 我不知道我在做什么错。