dimanche 20 décembre 2015

PHP: How to make testable static methods

I decided to make my own poor man's ORM framework. Since I did not know how to go about it I decide to develop before testing. Github. After making it work the way I want, I realise that my code was untestable because of the tight coupling between my static methods from the query class and BaseModel.

So I thought of some ways to make it testable:

  1. Make every query method receive a connection obect: But it means that when I try to consume these method in the BaseModel class I will still have to tightly couple the connection object to the BaseModel.
  2. Leave it the way it is: Which means during PHPUnit testing, I will have to override the BaseModel.

Whichever way, I feel that I am not doing the right thing. I believe that there is a better way I can go in making this work, and I need your help guys. Thanks

Aucun commentaire:

Enregistrer un commentaire