Asking for feedback on MDB2_Driver_mock draft
| From: | Torsten Roehr | Date: | Thu, 01 Jan 2009 13:16:08 +0000 |
| Subject: | Asking for feedback on MDB2_Driver_mock draft | ||
| Groups: | php.pear.dev | ||
| Request: | Send a blank email to pear-dev+get-51375@lists.php.net to get a copy of this message | ||
Hi devs,
I would like to get feedback on a first draft for an MDB2 mock driver. It's neither complete nor perfect yet but please take a look and express your opinion:
Zip: http://pear.zilleon.com/MDB2_Driver_mock/MDB2_Driver_mock.zip
Source code:
http://pear.zilleon.com/MDB2_Driver_mock/mock.php.txt
http://pear.zilleon.com/MDB2_Driver_mock/Datatype/mock.php.txt
http://pear.zilleon.com/MDB2_Driver_mock/tests/MDB2_Driver_mockTest.php.txt
It's heavily been borrowed from Greg Beaver's mockDB code used for testing pearweb (with his permission):
http://cvs.php.net/viewvc.cgi/pearweb/tests/mockDB/
For a better understanding of how it works please take a look at the example and the unit tests:
http://pear.zilleon.com/MDB2_Driver_mock/example.php.txt
http://pear.zilleon.com/MDB2_Driver_mock/tests/MDB2_Driver_mockTest.php.txt
There are methods to simulate fails as well to test that the application reacts to errors as expected:
For class MDB2_Driver_mock:
setConnectFails(true)
setPrepareFails(true)
setCharsetFails(true)
For class MDB2_Result_mock:
setFreeFails(true)
For class MDB2_Statement_mock:
setExecuteFails(true)
setFreeFails(true)
Maybe it's better to put the fail methods for the latter two classes into the driver class as well. What do you think?
Also, you can use getQueries() to validate that the queries you expected have been executed and in the correct order, e.g.:
$myObject = new MyObject();
$myObject->loadById(1)
$myObject->delete();
$phpunit->assertTrue($db->getQueries() === array("SELECT * FROM users WHERE id = 1",
"DELETE FROM users WHERE id = 1"));I'm looking forward to your feedback, thanks in advance. Best regards, Torsten (troehr)