我在一个测试中使用assertRedirectTo()时遇到了问题,以下是我使用的代码:
public function testLoggedInIndexAction() {
$this->dispatch('/');
$this->assertController('index');
$this->resetResponse();
$this->request->setPost(array(
'type' => 'login',
'username' => 'root',
'password' => 'asdasd',
));
$this->request->setMethod('POST');
$this->dispatch('/');
$this->assertRedirectTo('/feed/');
}
您可以通过 / (index.php/) 登录系统并提交帖子详情,接着会自动重定向到 /feed/ (index.php/feed/) 页面。我提供的信息是正确的,并且应该可以正常工作,但是我遇到了一个问题,PHPUnit 表明我的信息是不正确的:
There was 1 failure:
1) IndexControllerTest::testLoggedInIndexAction
Failed asserting response redirects to "/feed/"
/home/public_html/mashhr/library/Zend/Test/PHPUnit/Constraint/Redirect.php:190
/home/public_html/mashhr/library/Zend/Test/PHPUnit/ControllerTestCase.php:701
/home/public_html/mashhr/tests/application/controllers/UserControllerTest.php:36