我正在潜入单元测试的世界。我有点迷路了。今天我了解到单元测试正在测试函数是否有效。
我想测试以下功能:
public function getEventById($id)
{
return $this->getResource('Event')->getEventById($id);
}
所以我想测试一下这个函数:
public function test_Event_Get_Event_By_Id_Returns_Event_Item()
{
$p = $this->_model->getEventById(42);
$this->assertEquals(42, EventManager_Resource_Event_Item_Interface);
$this->assertType('EventManager_Resource_Event_Item_Interface', $p);
}
但后来我得到了错误:
1) EventTest::test_Event_Get_Event_By_Id_Returns_Event_Item
Zend_Db_Table_Exception: No adapter found for EventManager_Resource_Event
/home/user/Public/ZendFramework-1.10.1/library/SF/Model/Abstract.php:101
/var/www/nrka2/application/modules/eventManager/models/Event.php:25
但后来有人告诉我,我目前正在进行单元测试,而不是进行集成测试。所以我想我必须以不同的方式测试函数getEventByID。但我不明白怎么做。
此函数的作用是:只计算资源并按ID返回事件。