About unit testing a function in the zend framework and unit testing in general

Posted by sanders on Stack Overflow See other posts from Stack Overflow or by sanders
Published on 2010-06-15T16:19:44Z Indexed on 2010/06/15 16:22 UTC
Read the original article Hit count: 943

Filed under:
|
|

Hello people,

I am diving into the world of unit testing. And i am sort of lost. I learned today that unit testing is testing if a function works.

I wanted to test the following function:

public function getEventById($id)
{
    return $this->getResource('Event')->getEventById($id);
}

So i wanted to test this function as follows:

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);
}

But then I got the error:

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

But then someone told me that i am currently unit testing and not doing an integration test. So i figured that i have to test the function getEventById on a different way. But I don't understand how. What this function does it just cals a resource and returns the event by id.

© Stack Overflow or respective owner

Related posts about php

Related posts about unit-testing