如何在fuelphp中测试重定向
我写了一个这样的控制器如何在fuelphp中测试重定向,php,redirect,phpunit,fuelphp,Php,Redirect,Phpunit,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()
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());
这有点问题,它在数据库中插入了数据,但是当它运行重定向时,我无法重定向页面,所以测试失败了!为什么?这有什么问题。在我的理解中,您不能这样编写测试 因为
Response::redirect()
不返回任何内容,只返回用于重定向的HTTP头,并调用exit()
。因此,phpunit测试被exit()
中止
要使用Response::redirect()
测试代码,必须用test double替换Response::redirect()
方法