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


I'm diving into the world of unit testing. And I'm lost in a way I'd like to test if that is learned today is a function of work is so unit test I

I have the following function:

  public function getEventById ($ id) {return $ this- & gt; GetResource ('Event') - & gt; GetEventById ($ ID); }  

That's why I wanted to test follows this function:

  public function test_Event_Get_Event_By_Id_Returns_Event_Item () {$ p = $ this- & gt; _model- & gt; GetEventById (42); $ This- & gt; Emphasizing criteria (42, EventManager_Resource_Event_Item_Interface); $ This- & gt; Emphasis type ('EventManager_Resource_Event_Item_Interface', $ p); }  

But then I found the error:

  1) EventTest :: test_Event_Get_Event_By_Id_Returns_Event_Item Zend_Db_Table_Exception: No adapter found EventManager_Resource_Event / home / user / public / ZendFramework -1.10.1 / library / sf / model / Sarkfip: 101 /var/www/nrka2/application/modules/eventManager/models/Event.php:25  

but then Someone told me that I am currently testing the unit and am not doing an integration test. So I thought I had to test getEventById function in a different way. But I do not know how. What this function does, it straightens a resource and returns events by ID.

Well, a kind of object that you are testing him overload. After that you can override the getResource () method to return a "fake" object (one that can be sure to behave, and "set up" for each test). This trick is to separate the functionality that you want to test, and remove any dependencies (the getResource method in your code).

Some tutorials:

P>

( Note, this is for C #, but the concepts should be the same)


Comments

Popular posts from this blog

windows - Heroku throws SQLITE3 Read only exception -

lex - Building a lexical Analyzer in Java -

python - rename keys in a dictionary -