use Test::More qw(no_plan);
use strict;
use warnings;
use DBI;
my $dbh = DBI->connect('dbi:Mock:','','' );
my @session_ar =
( {
statement => "select foo,bar from baz where fi=?",
bound_params => [ 1 ],
results => [['foo','bar'],
['1foo','1bar']],
},
{
statement => "select foo,bar from baz where fi=?",
bound_params => [ 2 ],
results => [['foo','bar'],
['2foo','2bar']],
});
my $session = DBD::Mock::Session->new(@session_ar);
$dbh->{mock_session}=$session;
my $sth = $dbh->prepare("select foo,bar from baz where fi=?");
for my $i (1..2) {
$sth->execute($i);
my @result=$sth->fetchrow_array();
is($result[0],"${i}foo","Got right foo");
is($result[1],"${i}bar","Got right bar");
}
####
ok 1 - Got right foo
ok 2 - Got right bar
DBD::Mock::st execute failed: Session Error: Not the same number of bound params in current state in DBD::Mock::Session (Session 1) at /usr/share/perl5/DBD/Mock.pm line 1094. at t/90.dbd-mock.t line 28.
not ok 3 - Got right foo
# Failed test (t/90.dbd-mock.t at line 30)
# got: undef
# expected: '2foo'
not ok 4 - Got right bar
# Failed test (t/90.dbd-mock.t at line 31)
# got: undef
# expected: '2bar'
1..4
# Looks like you failed 2 tests of 4.
####
ok 1 - Got right foo
ok 2 - Got right bar
not ok 3 - Got right foo
# Failed test (t/90.dbd-mock.t at line 30)
# got: '1foo'
# expected: '2foo'
not ok 4 - Got right bar
# Failed test (t/90.dbd-mock.t at line 31)
# got: '1bar'
# expected: '2bar'
1..4
# Looks like you failed 2 tests of 4.