[CDBI] Class::DBI::MockDBD (was C::DBI and DBD::Mock problem)

Aaron Trevena aaron.trevena at gmail.com
Thu Mar 29 04:22:56 BST 2007


Hi All,

I now have DBD::Mock and Class::DBI working together :)

You need to over-ride sth_to_objects to use fetchrow_hashref instead
of bind_columns/fetch.

Also remember to populate the results first otherwise you get odd and
misleading errors.

To make it all much easier I'm bundling up the package I've built as
Class::DBI::MockDBD and putting it on CPAN.. the interface looks like
this :

In your ::DBI superclass :

"use base qw(Class::DBI::MockDBD);"

Your classes won't need a single line of code changed (with any luck)

In your test :

###############################

use ClassName;

# set up result
ClassName->next_result([ [qw/foo_id foo_name foo_bar/],[1,'aaaa','bbbb',]...]);

# run query
my $iterator = ClassName->search(...);

# get sql and params for query
my $sql = ClassName->last_query_info('statement');
my $params = ClassName->last_query_info('params');

#############################

I'll be uploading it to CPAN tomorrow once it's packaged up and meets
basic Koala Tea standards.

A.

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



More information about the ClassDBI mailing list