私はRob Allens ZF 1 チュートリアルに従い、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);
が問題を引き起こしているようです。そして、私はその理由を理解できません。すべてのアクションは正常に機能し、期待どおりに機能します。これを修正する方法はありますか?
ありがとう!