首页 > 解决方案 > 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);
    }

我认为这个问题是一个身份验证问题,我尝试按照文档中规定的所有身份验证工作。但是,它没有用。

有谁知道我可以如何进一步调试?任何帮助表示赞赏。谢谢你。

标签: cakephp-3.x

解决方案


推荐阅读