Zend framework $this->;fetchRow在Zend框架的phpunit中创建失败
我跟进了,并想通过一些单元测试来拉皮条。但每当我运行phpunit命令时,我都会得到以下消息:Zend framework $this->;fetchRow在Zend框架的phpunit中创建失败,zend-framework,phpunit,Zend Framework,Phpunit,我跟进了,并想通过一些单元测试来拉皮条。但每当我运行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/t
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.
我跟踪到错误是$wish>getWish($id)代码>因此,如果我转到该函数,它如下所示:
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);
}
}
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)代码>导致问题。我不知道为什么。所有的动作都很好,它们按预期进行。你知道如何解决这个问题吗
谢谢 如果是纯字符串:
public function getWish($id) {
$id = (int) $id;
$select = $this->select();
$select->where('id = ?', $id);
$row = $this->fetchRow($select);
if(!$row){
throw new Exception("Could not find row $id");
}
return $row->toArray();
}
这只是一个猜测,但谁知道呢。唯一奇怪的是查询字符串中缺少占位符(?)。
FetchRow()确实喜欢使用select()对象,事实上,如果传递字符串,FetchRow()要做的第一件事就是构建一个select()。也许它就是不喜欢这根绳子