Unit Testing In Yii Not Meant To Use Mock Objects?

Hi everyone!

I’ve been digging deeper and deeper into the concepts and ideologies around TDD. After reading a ton of articles on it, I’ve been trying to implement it with Yii. I’m having problems trying to figure out how to structure my code such that I can mock ActiveRecord classes…

Suppose I have a layer above my ActiveRecord classes to handle business logic. For now, let’s assume I have a “TranslationManager” class which makes calls to my ActiveRecord class “Translation”




class TranslationManager extends CComponent

{

    public function create($language, $translation)

    {

        $translation = new Translation();

        $translation->language = $language;

        $translation->translation = $translation;

        $translation->save();

    }

}



For the life of me I can’t figure out a way to mock test this situation. Perhaps this is a situation where I need to be using state testing (ie. with a temporary database) instead of behavioural testing (using mocks).

The other problem I foresee is that it’s going to be difficult testing any method that makes a static ActiveRecord call, like Translation::model()->findAll(). I’ve kind of come to my own conclusion that testing anything in Yii that deals with data access must be done with state testing (ie. using a temporary database) because mocking ActiveRecord objects seems weird…

Any thoughts on this? I’ve also read in a different thread that “Yii’s” way is using fixtures… which essentially is using a temporary database. I have some issues with this as I feel our tests shouldn’t be dependant on having a MySQL install. We COULD use sqlite but there are some incompatibilities between sqlite and MySQL.