This is a slightly thorny problem—when I was working on some tests with DBD::Mock, I tried to come up with a good general solution for this issue and the possibility of failure during a prepare call, and ran out of time to do it. I did come up with an adequate hack for this part, though:
@@ -1081,7 +1087,11 @@ # print STDERR "Adding Results: " . (join " | " => map { join ", " + => @{$_} } @{$current_state->{results}}) . "\n"; # copy the result sets so that # we can re-use the session - $dbh->STORE('mock_add_resultset' => [ @{$current_state->{results} +} ]); + if (my @results = @{$current_state->{results}} ) { + $dbh->STORE('mock_add_resultset' => [ @results ]); + } else { + $self->{state_index}++; + } } sub verify_bound_params {
To use it, you'd put an entry in the session looking like {statement => "select ...", results => [] } at the place you expected the prepare to happen, then normal entries for the execute calls.
Hope this helps!
In reply to Re: How to mock results to repeated $sth->execute() calls (DBD::Mock::Session)
by ChemBoy
in thread How to mock results to repeated $sth->execute() calls (DBD::Mock::Session)
by tirwhan
For: | Use: | ||
& | & | ||
< | < | ||
> | > | ||
[ | [ | ||
] | ] |