Skip to content
This repository was archived by the owner on Jan 5, 2023. It is now read-only.
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion lib/DBD/Mock/Session.pm
Original file line number Diff line number Diff line change
Expand Up @@ -178,7 +178,7 @@ sub _verify_bound_param {
. " expected: $expected";
}

if ( $got ne $expected ) {
if ( not $ref and $got ne $expected ) {
die "Bound param $index do not match "
. "in current state in DBD::Mock::Session ($self->{name})\n"
. " got: $got\n"
Expand Down
48 changes: 48 additions & 0 deletions t/031_DBD_Mock_Session_bound_params_regex.t
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
use strict;

use Test::More tests => 8;

BEGIN {
use_ok('DBD::Mock');
use_ok('DBI');
}

{
my $dbh = DBI->connect('dbi:Mock:', '', '', { RaiseError => 1, PrintError => 0 });
isa_ok($dbh, 'DBI::db');

my $session = DBD::Mock::Session->new((
{
statement => 'SELECT foo FROM bar WHERE baz = ?',
bound_params => [ qr/\d+/ ],
results => [[ 'foo' ], [ 10 ]]
},
{
statement => 'SELECT bar FROM foo WHERE baz = ?',
bound_params => [ qr/\d\d\d/ ],
results => [[ 'bar' ], [ 15 ]]
},
));
isa_ok($session, 'DBD::Mock::Session');

$dbh->{mock_session} = $session;

eval {
my $sth = $dbh->prepare('SELECT foo FROM bar WHERE baz = ?');
$sth->execute(100);
my ($result) = $sth->fetchrow_array();
is($result, 10, '... got the right value');
};
ok(!$@, '... everything worked as planned'.$@);

eval {
my $sth = $dbh->prepare('SELECT bar FROM foo WHERE baz = ?');
$sth->execute(125);
my ($result) = $sth->fetchrow_array();
is($result, 15, '... got the right value');
};
ok(!$@, '... everything worked as planned');

# Shuts up warning when object is destroyed
undef $dbh->{mock_session};
}