0
我跟在Rob Allens ZF 1 Tutorial之後,並希望用一些UnitTesting進行皮條客。但每當我運行PHPUnit的命令,我得到的消息:
here was 1 failure:
1) IndexControllerTest::testDeleteAction
Failed asserting last controller used <"error"> was "Index"
/path/to/library/Zend/Test/PHPUnit/ControllerTestCase.php:1000
/path/to/tests/application/controllers/IndexControllerTest.php:55
FAILURES!
Tests: 4, Assertions: 9, Failures: 1.
有問題的行動是deleteAction,看起來像這樣:
public function deleteAction() {
if ($this->getRequest()->isPost()) {
$del = $this->getRequest()->getPost('del');
if ($del == 'Yes') {
$id = $this->getRequest()->getPost('id');
$wishes = new Application_Model_DbTable_Wishes();
$wishes->deleteWish($id);
}
$this->_helper->redirector('index');
}
else {
$id = $this->_getParam('id', 0);
$wishes = new Application_Model_DbTable_Wishes();
$this->view->wish = $wishes->getWish($id);
}
}
我跟蹤誤差下拉至$wishes>getWish($id);
所以,如果我去那個功能,看起來像這樣:
public function getWish($id) {
$id = (int) $id;
$row = $this->fetchRow('id = ' . $id);
if(!$row){
throw new Exception("Could not find row $id");
}
return $row->toArray();
}
它出現行$row = $this->fetchRow('id = ' . $id);
導致問題。我無法弄清楚爲什麼。所有的行動工作都很好,他們按預期行事。任何想法如何解決這個問題?
謝謝!