From f23ed894adbb9b53ad41969a05291816bcc767a8 Mon Sep 17 00:00:00 2001 From: Gines Date: Mon, 6 May 2013 21:19:41 -0300 Subject: [PATCH] fixed check in bound params using regex --- lib/DBD/Mock/Session.pm | 2 +- t/031_DBD_Mock_Session_bound_params_regex.t | 48 +++++++++++++++++++++ 2 files changed, 49 insertions(+), 1 deletion(-) create mode 100644 t/031_DBD_Mock_Session_bound_params_regex.t diff --git a/lib/DBD/Mock/Session.pm b/lib/DBD/Mock/Session.pm index 912f36b..c269a7e 100644 --- a/lib/DBD/Mock/Session.pm +++ b/lib/DBD/Mock/Session.pm @@ -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" diff --git a/t/031_DBD_Mock_Session_bound_params_regex.t b/t/031_DBD_Mock_Session_bound_params_regex.t new file mode 100644 index 0000000..f9271db --- /dev/null +++ b/t/031_DBD_Mock_Session_bound_params_regex.t @@ -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}; +} \ No newline at end of file