2
我寫這樣如何測試重定向fuelphp
public function action_submit()
{
$submit = Format::forge(json_decode($_POST["submit"]))->to_array();
Servicecode::add_code_request($submit);
Response::redirect('code/codedetail');
}
然後我想寫PHPUnit來測試它的控制器,
public function test_adminsubmit()
{
$Submit = array(...);
$_POST["Submit"] = json_encode(Submit);
$response = Request::forge('code/codeeditrequest/submit')
->set_method('POST')
->execute()
->response();
$this->assertContains('ode Detail', $response->body->__toString());
什麼錯,它必須插入數據db,但是當它運行重定向時,我無法重定向頁面,所以測試失敗!WHy?這是怎麼回事?
謝謝,你解決了我的麻煩! – yang