|
From: Marcus B. <ma...@la...> - 2003-11-20 18:20:38
|
Hi... Jason Sweat wrote: > I guess the central question I am wrestling with relates to my earlier post > regarding testing of private methods, and what could be more private to an > object than it's database traffic ;) I am not sure that it should be private. What if you want to swap your database connection for one that does logging of all of the queries? Suddenly you want to swap it in and out. It is another form of interface after all. Have a look at the registry pattern in the phppatterns site (blatant self publicity I am afraid) for a way to manage singletons/globals. Here is another option, but more complicated. Move the database object creation into it's own factory method within your list thingy. Then you can subclass your main class to use a different connection object, such as a logging or mock version. It means that the class under test is slightly modified, but only for one method. The partial mocks in SimpleTest automate this somewhat, but I guess one pattern at a time. > I guess in an ideal world, you can just > test the public methods as a black box, but Mocks end up being the best > compromise in order to disconnect from the database and just test the remaining > logic. For hardcore testing all interfaces with the outside world (database, templates, network) should be replaceable. But then, I never get to the "ideal" world either so I can't talk. > > Thanks for putting up with my floundering around. > You seem to be doing extemely well. > Jason yours, Marcus -- Marcus Baker, ma...@la..., no...@ap... |