开发者

How to write Unit Test case for Zend Db Table Row

开发者 https://www.devze.com 2023-03-31 04:11 出处:网络
I am trying to write test case for my Row classes and I don\'t really what is the proper way todo that.

I am trying to write test case for my Row classes and I don't really what is the proper way to do that.

I've seen many example use model & table, for example http://techportal.inviqa.com/2010/12/07/unit-testing-databases-with-zend-framework/.

The case doesn't use Row at all and the model is all about getters and setters. I d开发者_JAVA百科on't want rewrite such things as the Zend_Db_Table_Row can do it automatically.

My row classes are extended from Zend_Db_Table_Row, I don't think there is necessary to write test cases like getters & setters.

And most my row classes are like following

class App_Table_Row_User extends Zend_Db_Table_Row_Abstract {

}

Then, in order to get a better test case coverage, what kind of test case I should write for a class like above?


I presume you need to populate object's attributes (table's column name => values) and run tests for your custom methods.

Zend_Db_Table_Row_Abstract constructor has one parameter - associative array with following keys:

  • table
  • data
  • stored
  • readOnly

To build useful for testing object you should use at least the "data" entries. It is associative array too. The "data" array has column names as keys and row data as values. So the testing object setUp may look as follows:

   $this->object = new App_Table_Row_User(     
     array(
       'data' => array(  
         'username' => 'Jon Doe',  
         'password' => 'qwerty',  
         'email' => 'j.doe@example.com'  
       )
     ) 
   );

You can pass NULL as values in the "data" array entries if you need something similar to the fetchNew return object.
If you are using "save" or any method that requires the table model, I will suggest using mock/stub object and passing it as the "table" parameter in the constructor. You can control any Db related operation that way.

Hope that helps :)

0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号