I am trying to test a class that controls access to data in a database (you know, CRUD, essentially). The DB library we use has an API in which you first get the table object with a static call:
function getFoo($id) { $MyTableRepresentation = DB_DataObject::factory("mytable"); $MyTableRepresentation->get($id); ... do some stuff return $somedata }
... you get the idea.
We are trying to test this method, but we are mocking DataObject so that (a) we donโt need the actual db connection for the test, and (b) we donโt even need to include DB_DataObject lib for the test.
However, in PHPUnit, I cannot get $ this-> getMock () to set up a static call. I have...
$DB_DataObject = $this->getMock('DB_DataObject', array('factory'));
... but the test still talks about the unknown "factory" method. I know that he creates an object because he said earlier that he could not find DB_DataObject. Now it is possible. But, no method?
What I really want to do is have two mock objects, one for the returned table object. Thus, I not only need to indicate that the factory is a static call, but also it returns some specific other layout that I have already configured.
I should mention as a warning that I did this in SimpleTest some time ago (I cannot find the code), and it worked fine.
What gives?
[UPDATE]
I'm starting to realize that it has something to do with expectations ()
source share