Subject: | Allow errstr to be set at runtime |
I want to use Test::MockDBI to test modules that checks the value of
DBI->errstr. The attached patch adds a function 'set_errstr()' to
MockDBI.pm that allows the value of DBI->errstr to be set at runtime.
Below is an example of how it can be used:
$ cat errstr.pl
# errstr.pl
use warnings;
use strict;
BEGIN { push @ARGV, "--dbitest=42"; }
use Test::More qw(no_plan);
use Test::MockDBI;
my $mock_dbi = Test::MockDBI::get_instance();
cmp_ok($mock_dbi->get_dbi_test_type(), q[==], 42, q{Expect test type 42});
# ------ set errstr to true
$mock_dbi->set_errstr('sql failed at line 53');
my $dbh = DBI->connect();
my $sth = $dbh->prepare('select foo from bar');
is($sth->errstr, 'sql failed at line 53', q{expect sth->errstr to be
defined});
($sth, $dbh) = (undef, undef);
# ------ set errstr to false
$mock_dbi->set_errstr();
$dbh = DBI->connect();
$sth = $dbh->prepare('select foo from bar');
ok(!$sth->errstr, q{expect sth->errstr to be undefined});
__END__
$ prove errstr.pl
errstr....ok
All tests successful.
Files=1, Tests=3, 0 wallclock secs ( 0.02 usr 0.01 sys + 0.02 cusr
0.00 csys = 0.05 CPU)
Result: PASS
Subject: | mockdbi.errstr.patch.tar.gz |
Message body not shown because it is not plain text.