DBI::Recorder

barbie on 2004-08-17T16:06:30

For a while this has been at the back of my mind. I like Test::MockObject, but setting it up for mocking the DBI can be a bit long winded sometimes. I like what HTTP::Recorder does, and DBI::Profile is half way to where I want to get to.

I want a module that can do two things;

  1. to be able to implement what DBI::Profile does, in terms of recording the SQL query and storing to a file, but in addition stores the result set that is returned by the DB, and can append to the file if requested to. Reading the docs, I can't see whether or how DBI::Profile can do this.
  2. to be able to translate that data file into a format that can be quickly plugged into a Test::MockObject backend, an as yet unwritten Test::MockObject::DBI module.

The aim would be to run a test suite, which outputs a file with all the necessary information passing between the application and the database, which can then be munged into a format which can replace the database using Test::MockObject.

The problem I've encountered so far is that, DBI::Profile only records the SQL queries being sent, and it recreates the profile file for each invocation rather than appends data. However, using this as a starting point, there should be no reason that I can't implement something similar. I can't find anything that looks like it can do what I want on CPAN (or Randy Kobes' site), although that may just be me not asking the right question. Note that I'm not after DBD::Mock, as I'm not testing the database calls, just that the munging of the result set is as expected.

So has anyone else thought of something like this? Can DBI::Profile do this? Is there some other module that already does this, or something similar? Is anyone working on a soon to be released distribution that does this? I did wonder whether, like HTTP::Recorder uses HTTP::Proxy, whether I could use DBI::ProxyServer, but that looks to be far too much effort for what I want.

I'm a big advocate of using Test::MockObject instead of trashing someones database. So I thought making life a little easier for anyone who wants to do the same, but can't face writing all the data files for the test suite, would be a good thing.

In other news Mark Stosberg released another version of CGI::Uploader. I have been meaning to finish off the Test::MockObject style testing for him for several months. Having DBI::Recorder would make that so much easier ;)


can plug some of this into DBD::Mock

lachoy on 2004-08-17T21:39:35

For your second item above, you can tell DBD::Mock to return results for either the nth SQL statement or for the statement matching the string x. So I don't think it would be too difficult to seed the database handle with the results from a given file -- something like a phrasebook with attached results. There aren't any hooks for creating such a file though.

(Note that I'm no longer maintaining this module -- as of yesterday Stevan Little has graciously taken it over at my request.)

please - pretty please

htoug on 2004-08-18T07:36:55

..find the tuits. I, for one, would find such a module immensely usefull.
My tuit supply has completely dried out (why does the boss expect me to do actual work?), otherwise I would have tried to do something like it myself, but I would be happy to help in any way I can.

Re:please - pretty please

barbie on 2004-08-18T09:13:48

Well I'm surprised no-one has tried it before. I'm on holiday next week, so will try and grab some time to investigate DBI::Profile further, and see if there are additional hooks I can use to get at the data. I may look at DBD::Mock for the end result, as this would require less work on my part, and already works :)