When you have an active record style model that uses a db adapter from a
registry, what's the best practise for unit testing?  Do you use a mock
object in the registry, use a test database, clean up the dev database after
inserting new records, or something else?

For instance, my User model has a save method like...

class User ....

        public function save() {
             ...
             $Db = Zend_Registry::get(REGISTRY_DB);
             if ($this->id) {
                 $Db->update(self::TABLE, $attributes, 'UserId='.$this->id);
             } else {
                 $attributes['DateCreated'] = date(MYSQL_DATE_FORMAT);
                 $Db->insert(self::TABLE, $attributes);
                 $this->id = $Db->lastInsertId();
            }
        }

and so, as the db adapter is held in a registry, it is not as
straightforward as normal to pass in a mock object for the db adapter.  How
do other people manage this situation (which must be awfully common)?  Do
you just allow yourself to write to the normal db and clean up afterwards
(so there aren't loads of test users in there)?  Or use a special testing db
so the mess doesn't matter?  Or something I've not thought of?
-- 
View this message in context: 
http://www.nabble.com/Unit-testing-active-record-models-tp18106086p18106086.html
Sent from the Zend Framework mailing list archive at Nabble.com.

Reply via email to