http://bugs.koha-community.org/bugzilla3/show_bug.cgi?id=5327 --- Comment #220 from Chris Cormack <chris@bigballofwax.co.nz> --- (In reply to comment #219)
Hello all,
Jonathan tells me to try DBD::Mock for one of my patch (Bug 5339), which I did. But I noticed some odd behaviour and I'm wondering if we are using it like we should. Example:
# This assume C4::Context::_new_dbh is mocked.
my $rs = [ ['id', 'column1', ...], [1, 'a', ...], [2, 'b', ...] ]; my $dbh = C4::Context->dbh; $dbh->{mock_add_resultset} = $rs; my @a = my_function();
my_function execute a single 'select' query and return data like in $rs, but in fact, even if my query is "SELECT * FROM bar WHERE id=1", it returns all the resultset. And even worse, if my query is something like "SELECT foo FROM bar", the whole resultset is still returned.
My question is: how can we use DBD::Mock for testing subroutines while subroutines will always return what we expect, and not what they should?
Is there something I'm doing wrong or something I don't understand?
Yep You can also associate a resultset with a particular SQL statement instead of adding them in the order they will be fetched: $dbh->{mock_add_resultset} = { sql => 'SELECT foo, bar FROM baz', results => [ [ 'foo', 'bar' ], [ 'this_one', 'that_one' ], [ 'this_two', 'that_two' ], ], }; http://search.cpan.org/~dichi/DBD-Mock-1.43/lib/DBD/Mock.pm -- You are receiving this mail because: You are watching all bug changes.