[CDBI] Class::DBI and DBD::Mock problem

Aaron Trevena aaron.trevena at gmail.com
Tue Mar 20 17:03:51 GMT 2007


On 20/03/07, Perrin Harkins <pharkins at gmail.com> wrote:
> On 3/20/07, Aaron Trevena <aaron.trevena at gmail.com> wrote:
> > the obvious thing to do is to use DBD::Mock and
> > populate some fake results, and check the params and statement
> > provided.

Note to self (and anybody else trying this) : You need to populate the
results in order for this to work :) d'oh.

> I'd only do that if it was totally impossible to test a real database.
>  Why don't you use your target db with some fake data?

Because I'm interested in checking that the generated query is ok -
and the results don't necessarily tell me that - so I need to see the
statement and parameters provided.

Basically, I'm using Traits (via Class::Trait) to add specialised
searching to classes in an application, these traits generate and run
complex queries using SQL::Abstract, and return a CDBI iterator (or
multiple cdbi iterators concatonated and wrapped in an iterator with
the same API).

It is much easier to test both the iterator and the query generation
if I can pre-populate the results and control whats going on without
having to worry about creating and populating a test database and
replicating all kinds of horrid geographical stuff.

Anyway - sorted now and making great progress with my testing.. once
I've mocked all the queries I'm going to mock TT.

A.

-- 
http://www.aarontrevena.co.uk
LAMP System Integration, Development and Hosting



More information about the ClassDBI mailing list