...
 
Commits (13)
use Module::Build;
use 5.006;
use 5.008001;
use strict;
use warnings;
......
Revision history for Perl extension DBD::Mock.
1.38 November 8, 2008
- Bumped minimum Perl to 5.8.1, since that's what DBI requires.
- Fixed incorrect use of no_plan in t/025_mock_last_insert_id.t.
- The handling of attributes passed to the constructor was not
correct. The major symptom was that attributes (such as
RaiseError) which were passed to the constructor could not be
overridden in the database handle which was returned from
connect(). As a result, some attributes set to a false value may
return '' instead of 0.
1.37 June 12, 2008
- New co-maintainer (aka sucker), Dave Rolsky
- Added support for $sth->bind_col() and $sth->bind_cols()
......
......@@ -13,14 +13,14 @@ sub import {
# License or the Artistic License, as specified in the Perl README file.
# --------------------------------------------------------------------------- #
use 5.006;
use 5.008001;
use strict;
use warnings;
require DBI;
our $VERSION = '1.37';
our $VERSION = '1.38';
our $drh = undef; # will hold driver handle
our $err = 0; # will hold any error codes
......@@ -105,35 +105,26 @@ sub connect {
return;
}
$attributes ||= {};
if ($dbname && $DBD::Mock::AttributeAliasing) {
# this is the DB we are mocking
$attributes->{mock_attribute_aliases} = DBD::Mock::_get_mock_attribute_aliases($dbname);
$attributes->{mock_database_name} = $dbname;
}
# Need to protect AutoCommit from $dbh caching - RobK.
my $autocommit = 1;
if( exists $attributes->{ 'AutoCommit' } ) {
$autocommit = delete $attributes->{ 'AutoCommit' };
}
my $dbh = DBI::_new_dbh($drh, {
Name => $dbname,
# holds statement parsing coderefs/objects
mock_parser => [],
# holds all statements applied to handle until manually cleared
mock_statement_history => [],
# ability to fake a failed DB connection
mock_can_connect => 1,
# ability to make other things fail :)
mock_can_prepare => 1,
mock_can_execute => 1,
mock_can_fetch => 1,
# rest of attributes
%{ $attributes },
}) || return;
# holds statement parsing coderefs/objects
$attributes->{mock_parser} = [];
# holds all statements applied to handle until manually cleared
$attributes->{mock_statement_history} = [];
# ability to fake a failed DB connection
$attributes->{mock_can_connect} = 1;
# ability to make other things fail :)
$attributes->{mock_can_prepare} = 1;
$attributes->{mock_can_execute} = 1;
$attributes->{mock_can_fetch} = 1;
$dbh->STORE( 'AutoCommit' => $autocommit );
my $dbh = DBI::_new_dbh($drh, {Name => $dbname})
|| return;
return $dbh;
}
......@@ -405,16 +396,11 @@ sub selectcol_arrayref {
return [ map { @$_[@cols] } @{$a_ref} ]
}
{
my %autocommit;
sub FETCH {
my ( $dbh, $attrib ) = @_;
my ( $dbh, $attrib, $value ) = @_;
$dbh->trace_msg( "Fetching DB attrib '$attrib'\n" );
if ($attrib eq 'AutoCommit') {
$dbh->trace_msg( "Fetching AutoCommit\n" );
return $autocommit{$dbh};
}
elsif ($attrib eq 'Active') {
if ($attrib eq 'Active') {
return $dbh->{mock_can_connect};
}
elsif ($attrib eq 'mock_all_history') {
......@@ -450,11 +436,14 @@ sub FETCH {
sub STORE {
my ( $dbh, $attrib, $value ) = @_;
$dbh->trace_msg( "Storing DB attribute '$attrib' with '" . (defined($value) ? $value : 'undef') . "'\n" );
if ($attrib eq 'AutoCommit') {
$autocommit{$dbh} = $value;
return $value;
# These are magic DBI values that say we can handle AutoCommit
# internally as well
$value = ($value) ? -901 : -900;
}
elsif ( $attrib eq 'mock_clear_history' ) {
if ( $attrib eq 'mock_clear_history' ) {
if ( $value ) {
$dbh->{mock_statement_history} = [];
}
......@@ -539,11 +528,10 @@ sub STORE {
return $dbh->SUPER::STORE($attrib, $value);
}
else {
$dbh->trace_msg("... storing non-driver attribute ($attrib) with value ($value) that DBI wont handle\n");
$dbh->trace_msg("... storing non-driver attribute ($attrib) with value ($value) that DBI won't handle\n");
return $dbh->{$attrib} = $value;
}
}
}
sub DESTROY {
my ($dbh) = @_;
......@@ -932,11 +920,14 @@ use warnings;
my $connection;
sub connect {
my $class = "DBD::Mock::Pool";
$class = shift unless ref($_[0]);
my ($driver_handle, $username, $password, $attributes) = @_;
$connection = bless $driver_handle->connect(), "DBD::Mock::Pool::db" unless $connection;
return $connection;
return $connection if $connection;
# according to the code before my tweaks, this could be a class
# name, but it was never used - DR, 2008-11-08
shift unless ref $_[0];
my $drh = shift;
return $connection = bless $drh->connect(@_), 'DBD::Mock::Pool::db';
}
package DBD::Mock::Pool::db;
......@@ -1372,7 +1363,7 @@ To do that our test might look like:
# Now query that history record to
# see if our expectations match reality
cmp_ok(scalar(@{$history}), '==', 1, 'Correct number of statements executed' ;
is(scalar(@{$history}), 1, 'Correct number of statements executed' ;
my $login_st = $history->[0];
like($login_st->statement,
......@@ -1380,7 +1371,7 @@ To do that our test might look like:
'Correct statement generated' );
my $params = $login_st->bound_params;
cmp_ok(scalar(@{$params}), '==', 1, 'Correct number of parameters bound');
is(scalar(@{$params}), 1, 'Correct number of parameters bound');
is($params->[0], $login_name, 'Correct value for parameter 1' );
# Reset the handle for future operations
......
use strict;
use Test::More tests => 20;
use Test::More tests => 24;
BEGIN {
use_ok('DBD::Mock');
......@@ -14,25 +14,25 @@ BEGIN {
isa_ok($dbh, 'DBI::db');
is($dbh->{Name}, '', '... if no db-name is given');
cmp_ok( $dbh->{AutoCommit}, '==', 1,
ok( $dbh->{AutoCommit},
'... AutoCommit DB attribute defaults to set' );
# DBI will handle attributes with 'private_', 'dbi_' or ,
# 'dbd_' prefixes but all others, we need to handle.
$dbh->{mysql_insertid} = 10;
cmp_ok($dbh->{mysql_insertid}, '==', 10, '... this attribute should be 10');
is($dbh->{mysql_insertid}, 10, '... this attribute should be 10');
# DBI will handle these
$dbh->{private_insert_id} = 15;
cmp_ok($dbh->{private_insert_id}, '==', 15, '... this attribute should be 15');
is($dbh->{private_insert_id}, 15, '... this attribute should be 15');
$dbh->{dbi_attribute} = 2000;
cmp_ok($dbh->{dbi_attribute}, '==', 2000, '... this attribute should be 2000');
is($dbh->{dbi_attribute}, 2000, '... this attribute should be 2000');
$dbh->{dbd_attr} = 15_000;
cmp_ok($dbh->{dbd_attr}, '==', 15_000, '... this attribute should be 15,000');
is($dbh->{dbd_attr}, 15_000, '... this attribute should be 15,000');
$dbh->disconnect();
}
......@@ -46,11 +46,11 @@ BEGIN {
$dbh->{PrintError} = 1;
$dbh->{AutoCommit} = 1;
cmp_ok( $dbh->{RaiseError}, '==', 1,
ok( $dbh->{RaiseError},
'RaiseError DB attribute set after connect()' );
cmp_ok( $dbh->{PrintError}, '==', 1,
ok( $dbh->{PrintError},
'PrintError DB attribute set after connect()' );
cmp_ok( $dbh->{AutoCommit}, '==', 1,
ok( $dbh->{AutoCommit},
'AutoCommit DB attribute set after connect()' );
$dbh->disconnect();
......@@ -63,28 +63,28 @@ BEGIN {
{ RaiseError => 1,
PrintError => 1,
AutoCommit => 1 } );
cmp_ok( $dbh->{RaiseError}, '==', 1,
ok( $dbh->{RaiseError},
'RaiseError DB attribute set in connect()' );
cmp_ok( $dbh->{PrintError}, '==', 1,
ok( $dbh->{PrintError},
'PrintError DB attribute set in connect()' );
cmp_ok( $dbh->{AutoCommit}, '==', 1,
ok( $dbh->{AutoCommit},
'AutoCommit DB attribute set in connect()' );
$dbh->disconnect();
}
# test setting attributes with negative values during connect
# test setting attributes with false values during connect
{
my $dbh = DBI->connect( 'DBI:Mock:', '', '',
{ RaiseError => 0,
PrintError => 0,
AutoCommit => 0 } );
cmp_ok( $dbh->{RaiseError}, '==', 0,
ok( ! $dbh->{RaiseError},
'RaiseError DB attribute unset in connect()' );
cmp_ok( $dbh->{PrintError}, '==', 0,
ok( ! $dbh->{PrintError},
'PrintError DB attribute unset in connect()' );
cmp_ok( $dbh->{AutoCommit}, '==', 0,
ok( ! $dbh->{AutoCommit},
'AutoCommit DB attribute unset in connect()' );
$dbh->disconnect();
......@@ -106,3 +106,27 @@ BEGIN {
'... got the right data sources');
}
{
my $dbh = DBI->connect( 'DBI:Mock:', '', '',
{ RaiseError => 0,
PrintError => 0,
PrintWarn => 0,
AutoCommit => 0,
} );
$dbh->{RaiseError} = 1;
$dbh->{PrintError} = 1;
$dbh->{PrintWarn} = 1;
$dbh->{AutoCommit} = 1;
ok( $dbh->{RaiseError},
'RaiseError DB attribute set in connect() and then changed' );
ok( $dbh->{PrintError},
'PrintError DB attribute set in connect() and then changed' );
ok( $dbh->{PrintWarn},
'PrintWarn DB attribute set in connect() and then changed' );
ok( $dbh->{AutoCommit},
'AutoCommit DB attribute set in connect() and then changed' );
$dbh->disconnect();
}
......@@ -53,7 +53,7 @@ is_deeply(
}
{ # check the mock_connect_fail attribute
cmp_ok($drh->{mock_connect_fail}, '==', 0, '... the default is set not to fail');
is($drh->{mock_connect_fail}, 0, '... the default is set not to fail');
# make sure the this only affects the initial connect
my $_dbh = DBI->connect('dbi:Mock:', '', '', { RaiseError => 1, PrintError => 0 });
......@@ -61,7 +61,7 @@ is_deeply(
# now no more connections
$drh->{mock_connect_fail} = 1;
cmp_ok($drh->{mock_connect_fail}, '==', 1, '... we are set to fail');
is($drh->{mock_connect_fail}, 1, '... we are set to fail');
eval {
DBI->connect('dbi:Mock:', '', '', { RaiseError => 1, PrintError => 0 });
......@@ -76,7 +76,7 @@ is_deeply(
ok(!$@, '... we should not have an exception here');
$drh->{mock_connect_fail} = 0;
cmp_ok($drh->{'mock_connect_fail'}, '==', 0, '... we are set not to fail');
is($drh->{'mock_connect_fail'}, 0, '... we are set not to fail');
my $dbh;
eval {
......
......@@ -13,7 +13,7 @@ BEGIN {
isa_ok($dbh, "DBI::db");
# check to be sure this is set, otherwise
# the test wont be set up right
cmp_ok($dbh->{RaiseError}, '==', 1, '... make sure RaiseError is set correctly');
is($dbh->{RaiseError}, 1, '... make sure RaiseError is set correctly');
# check to see it is active in the first place
ok($dbh->{Active}, '...our handle with the default settting is Active' );
......@@ -22,7 +22,7 @@ BEGIN {
$dbh->{mock_can_connect} = 0;
# check our value is correctly set
cmp_ok($dbh->{mock_can_connect}, '==', 0, '... can connect is set to 0');
is($dbh->{mock_can_connect}, 0, '... can connect is set to 0');
# and check the side effects of that
ok(!$dbh->{Active}, '...our handle is no longer Active after setting mock_can_connect');
......@@ -49,7 +49,7 @@ BEGIN {
isa_ok($dbh, "DBI::db");
# check to be sure this is set, otherwise
# the test wont be set up right
cmp_ok($dbh->{PrintError}, '==', 1, '... make sure PrintError is set correctly');
is($dbh->{PrintError}, 1, '... make sure PrintError is set correctly');
# check to see it is active in the first place
ok($dbh->{Active}, '...our handle with the default settting is Active' );
......@@ -58,7 +58,7 @@ BEGIN {
$dbh->{mock_can_connect} = 0;
# check our value is correctly set
cmp_ok($dbh->{mock_can_connect}, '==', 0, '... can connect is set to 0');
is($dbh->{mock_can_connect}, 0, '... can connect is set to 0');
# and check the side effects of that
ok(!$dbh->{Active}, '...our handle is no longer Active after setting mock_can_connect');
......
......@@ -13,21 +13,21 @@ my $dbh = DBI->connect('DBI:Mock:', '', '');
isa_ok($dbh, 'DBI::db');
$dbh->{AutoCommit} = 1;
cmp_ok($dbh->{AutoCommit}, '==', 1, '... it handles AutoCommit as well');
ok($dbh->{AutoCommit}, '... it handles AutoCommit as well');
$dbh->{AutoCommit} = 0;
cmp_ok($dbh->{AutoCommit}, '==', 0, '... and turns off AutoCommit as well');
ok(! $dbh->{AutoCommit}, '... and turns off AutoCommit as well');
for (0 .. 5) {
my $sth = $dbh->prepare('SELECT * FROM foo');
$sth->execute();
}
cmp_ok(scalar(@{$dbh->{mock_all_history}}), '==', 6, '... we have 6 statements');
is(scalar(@{$dbh->{mock_all_history}}), 6, '... we have 6 statements');
$dbh->{mock_clear_history} = 1;
cmp_ok(scalar(@{$dbh->{mock_all_history}}), '==', 0, '... we have 0 statements');
is(scalar(@{$dbh->{mock_all_history}}), 0, '... we have 0 statements');
# test the misc. attributes of $sth
......@@ -67,10 +67,10 @@ is_deeply(
'... we have 3 records');
# mock_num_records
cmp_ok($sth->{mock_num_records}, '==', 3, '... we have 3 records');
is($sth->{mock_num_records}, 3, '... we have 3 records');
# mock_current_record_num
cmp_ok($sth->{mock_current_record_num}, '==', 0, '... we are at record number 0');
is($sth->{mock_current_record_num}, 0, '... we are at record number 0');
# mock_is_finished
is($sth->{mock_is_finished}, 'no', '... we are not yet finished');
......@@ -79,8 +79,8 @@ is($sth->{mock_is_finished}, 'no', '... we are not yet finished');
ok(!$sth->{mock_is_depleted}, '... nor are we depleted');
for (1 .. 3) {
cmp_ok(($sth->fetchrow_array())[0], '==', $_, '... got the expected row');
cmp_ok($sth->{mock_current_record_num}, '==', $_, '... we are at record number ' . $_);
is(($sth->fetchrow_array())[0], $_, '... got the expected row');
is($sth->{mock_current_record_num}, $_, '... we are at record number ' . $_);
}
# mock_is_depleted
......
......@@ -12,7 +12,7 @@ BEGIN {
isa_ok($dbh, "DBI::db");
# check to be sure this is set, otherwise
# the test wont be set up right
cmp_ok($dbh->{RaiseError}, '==', 1, '... make sure RaiseError is set correctly');
is($dbh->{RaiseError}, 1, '... make sure RaiseError is set correctly');
# check parse sub-refs
......@@ -57,7 +57,7 @@ BEGIN {
isa_ok($dbh, "DBI::db");
# check to be sure this is set, otherwise
# the test wont be set up right
cmp_ok($dbh->{PrintError}, '==', 1, '... make sure PrintError is set correctly');
is($dbh->{PrintError}, 1, '... make sure PrintError is set correctly');
# check parse objects
......@@ -94,7 +94,7 @@ BEGIN {
isa_ok($dbh, "DBI::db");
# check to be sure this is set, otherwise
# the test wont be set up right
cmp_ok($dbh->{RaiseError}, '==', 1, '... make sure RaiseError is set correctly');
is($dbh->{RaiseError}, 1, '... make sure RaiseError is set correctly');
eval {
$dbh->{mock_add_parser} = "Fail";
......@@ -115,7 +115,7 @@ BEGIN {
isa_ok($dbh, "DBI::db");
# check to be sure this is set, otherwise
# the test wont be set up right
cmp_ok($dbh->{PrintError}, '==', 1, '... make sure PrintError is set correctly');
is($dbh->{PrintError}, 1, '... make sure PrintError is set correctly');
{ # isolate the warn handler
local $SIG{__WARN__} = sub {
......
......@@ -14,18 +14,18 @@ foreach my $i ( 1 .. 2 ) {
my $sth = $dbh->prepare('SELECT foo FROM bar WHERE x = ?');
$sth->execute($i);
my $history = $dbh->{mock_all_history};
cmp_ok(scalar(@{$history}), '==', $i, "... have $i statement executions");
is(scalar(@{$history}), $i, "... have $i statement executions");
}
$dbh->{mock_clear_history} = 1;
my $history = $dbh->{mock_all_history};
cmp_ok(scalar(@{$history}), '==', 0, '... the history has been is cleared');
is(scalar(@{$history}), 0, '... the history has been is cleared');
foreach my $i ( 1 .. 2 ) {
my $sth = $dbh->prepare_cached('SELECT foo FROM bar WHERE x = ?');
$sth->execute($i);
my $history = $dbh->{mock_all_history};
cmp_ok(scalar(@{$history}), '==', $i, "... have $i statement executions");
is(scalar(@{$history}), $i, "... have $i statement executions");
}
my $st_track = $dbh->{mock_all_history}->[0];
......@@ -34,4 +34,4 @@ isa_ok($st_track, 'DBD::Mock::StatementTrack');
is($st_track->statement, 'SELECT foo FROM bar WHERE x = ?', '... our statements match');
my $params = $st_track->bound_params;
cmp_ok(scalar(@{$params}), '==', 1, '... got the expected amount of params');
is(scalar(@{$params}), 1, '... got the expected amount of params');
......@@ -60,7 +60,7 @@ like($@, qr/Attribute aliases not available for \'Fail\'/, '... got the error we
$sth->execute();
cmp_ok($dbh->{mysql_insertid}, '==', 1, '... our alias works');
is($dbh->{mysql_insertid}, 1, '... our alias works');
}
......@@ -83,6 +83,6 @@ like($@, qr/Attribute aliases not available for \'Fail\'/, '... got the error we
$sth->execute();
cmp_ok($dbh->{mysql_insertid}, '==', 1, '... our alias works');
is($dbh->{mysql_insertid}, 1, '... our alias works');
}
......@@ -22,8 +22,8 @@ BEGIN {
is($sth->{Statement}, 'SELECT Foo, Bar, Baz FROM FooBarBaz', '... got the right statement');
is($sth->{Database}, $dbh, '... got the right Database handle');
cmp_ok($sth->{NUM_OF_FIELDS}, '==', 3, '... got the right number of fields');
cmp_ok($sth->{NUM_OF_PARAMS}, '==', 0, '... got the right number of params');
is($sth->{NUM_OF_FIELDS}, 3, '... got the right number of fields');
is($sth->{NUM_OF_PARAMS}, 0, '... got the right number of params');
is_deeply(
$sth->{NAME},
......
......@@ -31,7 +31,7 @@ $dbh->{mock_add_resultset} = {
my ($result) = $sth->fetchrow_array();
cmp_ok($result, '==', 10, '... got the result we expected');
is($result, 10, '... got the result we expected');
$sth->finish();
}
......@@ -50,7 +50,7 @@ $dbh->{mock_add_resultset} = {
my ($result) = $sth->fetchrow_array();
cmp_ok($result, '==', 50, '... got the result we expected');
is($result, 50, '... got the result we expected');
$sth->finish();
}
......@@ -65,7 +65,7 @@ $dbh->{mock_add_resultset} = {
my ($result) = $sth->fetchrow_array();
cmp_ok($result, '==', 50, '... got the result we expected');
is($result, 50, '... got the result we expected');
$sth->finish();
}
......@@ -80,7 +80,7 @@ $dbh->{mock_add_resultset} = {
my ($result) = $sth->fetchrow_array();
cmp_ok($result, '==', 50, '... got the result we expected');
is($result, 50, '... got the result we expected');
$sth->finish();
}
......
......@@ -9,8 +9,8 @@ BEGIN {
my $dbh = DBI->connect('DBI:Mock:', '', '', { RaiseError => 1, PrintError => 0 });
isa_ok($dbh, "DBI::db");
cmp_ok($dbh->{RaiseError}, '==', 1, '... RaiseError is set correctly');
cmp_ok($dbh->{PrintError}, '==', 0, '... PrintError is set correctly');
ok($dbh->{RaiseError}, '... RaiseError is set correctly');
ok(! $dbh->{PrintError}, '... PrintError is set correctly');
my $sth_exec = $dbh->prepare('SELECT foo FROM bar');
isa_ok($sth_exec, "DBI::st");
......@@ -19,7 +19,7 @@ isa_ok($sth_exec, "DBI::st");
$dbh->{mock_can_connect} = 0;
# check our value is correctly set
cmp_ok($dbh->{mock_can_connect}, '==', 0, '... can connect is set to 0');
is($dbh->{mock_can_connect}, 0, '... can connect is set to 0');
# and check the side effects of that
ok(!$dbh->{Active}, '... the handle is not Active');
......@@ -36,7 +36,7 @@ like($@, qr/No connection present/, '... we got the expected execption');
$dbh->{mock_can_connect} = 1;
# check our value is correctly set
cmp_ok($dbh->{mock_can_connect}, '==', 1, '... can connect is set to 1');
is($dbh->{mock_can_connect}, 1, '... can connect is set to 1');
# and check the side effects of that
ok($dbh->{Active}, '... the handle is Active');
......@@ -60,7 +60,7 @@ is_deeply($row, [ qw(this that) ], '... we got back the expected data in the fir
$dbh->{mock_can_connect} = 0;
# check our value is correctly set
cmp_ok($dbh->{mock_can_connect}, '==', 0, '... can connect is set to 0');
is($dbh->{mock_can_connect}, 0, '... can connect is set to 0');
# and check the side effects of that
ok(!$dbh->{Active}, '... the handle is not Active');
......
......@@ -35,15 +35,15 @@ BEGIN {
my $st_track = DBD::Mock::StatementTrack->new();
isa_ok($st_track, 'DBD::Mock::StatementTrack');
cmp_ok($st_track->num_fields(), '==', 0, '... we have no fields in the default');
is($st_track->num_fields(), 0, '... we have no fields in the default');
is_deeply($st_track->fields(), [], '... we have no fields in the default');
cmp_ok($st_track->num_params(), '==', 0, '... we have no bound params in the default');
is($st_track->num_params(), 0, '... we have no bound params in the default');
is_deeply($st_track->bound_params(), [], '... we have no bound params in the default');
is_deeply($st_track->return_data(), [], '... we have no return data in the default');
cmp_ok($st_track->current_record_num(), '==', 0, '... our current record num is 0 in the default');
is($st_track->current_record_num(), 0, '... our current record num is 0 in the default');
is($st_track->statement(), '', '... our statement is a blank string in the default');
is($st_track->is_executed(), 'no', '... our statement is not executed in the default');
......@@ -53,7 +53,7 @@ BEGIN {
is($st_track->is_finished(), 'no', '... our statement is not finished in the default');
cmp_ok($st_track->is_active(), '==', 0, '... the default state is not active');
is($st_track->is_active(), 0, '... the default state is not active');
}
{ # check a pre-defined state
......@@ -68,15 +68,15 @@ BEGIN {
my $st_track = DBD::Mock::StatementTrack->new(%params);
isa_ok($st_track, 'DBD::Mock::StatementTrack');
cmp_ok($st_track->num_fields(), '==', 3, '... we have the expected num of fields');
is($st_track->num_fields(), 3, '... we have the expected num of fields');
is_deeply($st_track->fields(), $params{fields}, '... we have the expected fields');
cmp_ok($st_track->num_params(), '==', 1, '... we have the expected num of bound params');
is($st_track->num_params(), 1, '... we have the expected num of bound params');
is_deeply($st_track->bound_params(), $params{bound_params}, '... we have the expected bound params');
is_deeply($st_track->return_data(), $params{return_data}, '... we have the expected return data');
cmp_ok($st_track->current_record_num(), '==', 0, '... our current record num is 0 in the default');
is($st_track->current_record_num(), 0, '... our current record num is 0 in the default');
is($st_track->statement(), $params{statement}, '... our statement as expected ');
is($st_track->is_executed(), 'no', '... our statement is not executed');
......@@ -85,7 +85,7 @@ BEGIN {
is($st_track->is_finished(), 'no', '... our statement is not finished');
cmp_ok($st_track->is_active(), '==', 0, '... the default state is active');
is($st_track->is_active(), 0, '... the default state is active');
# now lets alter that state
# and make sure changes reflect
......@@ -101,7 +101,7 @@ BEGIN {
[ 'baz', 'foo', 'bar', 'foobar' ],
'... we have the expected bound params');
cmp_ok($st_track->num_params(), '==', 4, '... we have the expected num of bound params');
is($st_track->num_params(), 4, '... we have the expected num of bound params');
{
my $old_SQL = $st_track->statement();
......@@ -110,7 +110,7 @@ BEGIN {
$st_track->statement($SQL);
is($st_track->statement(), $SQL, '... our statement as expected ');
cmp_ok($st_track->is_active(), '==', 0, '... with an INSERT we are not considered active');
is($st_track->is_active(), 0, '... with an INSERT we are not considered active');
$st_track->statement($old_SQL);
......@@ -119,9 +119,9 @@ BEGIN {
$st_track->mark_executed();
is($st_track->is_executed(), 'yes', '... our statement is now executed');
cmp_ok($st_track->current_record_num(), '==', 0, '... our current record num is 0');
is($st_track->current_record_num(), 0, '... our current record num is 0');
cmp_ok($st_track->is_active(), '==', 1, '... we are active now that we are executed');
is($st_track->is_active(), 1, '... we are active now that we are executed');
for (1 .. 3) {
ok(!$st_track->is_depleted(), '... the state is not depleted');
......@@ -129,13 +129,13 @@ BEGIN {
$st_track->next_record(),
[ $_, $_, $_ ],
'... got the next record as expected');
cmp_ok($st_track->current_record_num(), '==', $_, '... our current record num is now ' . $_);
is($st_track->current_record_num(), $_, '... our current record num is now ' . $_);
}
ok(!defined($st_track->next_record()), '... no more records');
ok($st_track->is_depleted(), '... we are now depleted');
cmp_ok($st_track->is_active(), '==', 0, '... we are no longer active now that we are depleted');
is($st_track->is_active(), 0, '... we are no longer active now that we are depleted');
is($st_track->is_finished(), 'no', '... passing in nothing just returns the value');
......
......@@ -11,20 +11,20 @@ BEGIN {
my $i = DBD::Mock::StatementTrack::Iterator->new([ 1 .. 5 ]);
isa_ok($i, 'DBD::Mock::StatementTrack::Iterator');
cmp_ok($i->next(), '==', 1, '... got 1');
cmp_ok($i->next(), '==', 2, '... got 2');
cmp_ok($i->next(), '==', 3, '... got 3');
cmp_ok($i->next(), '==', 4, '... got 4');
cmp_ok($i->next(), '==', 5, '... got 5');
is($i->next(), 1, '... got 1');
is($i->next(), 2, '... got 2');
is($i->next(), 3, '... got 3');
is($i->next(), 4, '... got 4');
is($i->next(), 5, '... got 5');
ok(!defined($i->next()), '... got undef');
$i->reset();
cmp_ok($i->next(), '==', 1, '... got 1');
cmp_ok($i->next(), '==', 2, '... got 2');
cmp_ok($i->next(), '==', 3, '... got 3');
cmp_ok($i->next(), '==', 4, '... got 4');
cmp_ok($i->next(), '==', 5, '... got 5');
is($i->next(), 1, '... got 1');
is($i->next(), 2, '... got 2');
is($i->next(), 3, '... got 3');
is($i->next(), 4, '... got 4');
is($i->next(), 5, '... got 5');
ok(!defined($i->next()), '... got undef');
}
......
......@@ -10,10 +10,10 @@ BEGIN {
# check that the pool works
{
my $dbh = DBI->connect("DBI:Mock:", '', '');
my $dbh = DBI->connect("DBI:Mock:", '', '', {RaiseError => 1 });
isa_ok($dbh, 'DBD::Mock::Pool::db');
my $dbh2 = DBI->connect("DBI:Mock:", '', '');
my $dbh2 = DBI->connect("DBI:Mock:", '', '', {RaiseError => 1 });
isa_ok($dbh2, 'DBD::Mock::Pool::db');
is($dbh, $dbh2, '... these handles should be the same');
......@@ -28,7 +28,7 @@ BEGIN {
{
# set up handle from pool
my $dbh = DBI->connect("DBI:Mock:", '', '');
my $dbh = DBI->connect("DBI:Mock:", '', '', {RaiseError => 1 });
isa_ok($dbh, 'DBD::Mock::Pool::db');
$dbh->{mock_add_resultset} = [[ 'foo', 'bar', 'baz' ], [ 1, 2, 3 ]];
......@@ -38,7 +38,7 @@ BEGIN {
{
# execute a statement, and expect the results
my $dbh = DBI->connect("DBI:Mock:", '', '');
my $dbh = DBI->connect("DBI:Mock:", '', '', {RaiseError => 1 });
isa_ok($dbh, 'DBD::Mock::Pool::db');
my $sth = $dbh->prepare("SELECT foo, bar, baz FROM whatever");
......@@ -54,13 +54,13 @@ BEGIN {
}
{
# check our statement istory
# check our statement history
my $dbh = DBI->connect("DBI:Mock:", '', '');
isa_ok($dbh, 'DBD::Mock::Pool::db');
my $history = $dbh->{mock_all_history};
cmp_ok(scalar @{$history}, '==', 1, '... we executed 1 statement');
is(scalar @{$history}, 1, '... we executed 1 statement');
is( $history->[0]->statement(),
"SELECT foo, bar, baz FROM whatever",
......
......@@ -31,7 +31,7 @@ BEGIN {
my $sth = $dbh->prepare('SELECT foo FROM bar WHERE baz = ?');
$sth->execute(100);
my ($result) = $sth->fetchrow_array();
cmp_ok($result, '==', 10, '... got the right value');
is($result, 10, '... got the right value');
};
ok(!$@, '... everything worked as planned');
......@@ -39,7 +39,7 @@ BEGIN {
my $sth = $dbh->prepare('SELECT bar FROM foo WHERE baz = ?');
$sth->execute(125);
my ($result) = $sth->fetchrow_array();
cmp_ok($result, '==', 15, '... got the right value');
is($result, 15, '... got the right value');
};
ok(!$@, '... everything worked as planned');
......@@ -75,7 +75,7 @@ BEGIN {
my $sth = $dbh->prepare('SELECT foo FROM bar WHERE baz = ?');
$sth->execute(100);
my ($result) = $sth->fetchrow_array();
cmp_ok($result, '==', 10, '... got the right value');
is($result, 10, '... got the right value');
};
ok(!$@, '... first state worked as planned');
......@@ -83,14 +83,14 @@ BEGIN {
my $sth = $dbh->prepare('SELECT bar FROM foo WHERE baz = 125');
$sth->execute();
my ($result) = $sth->fetchrow_array();
cmp_ok($result, '==', 15, '... got the right value');
is($result, 15, '... got the right value');
};
ok(!$@, '... second state worked as planned');
eval {
my $sth = $dbh->prepare('DELETE FROM bar WHERE baz = ?');
$sth->execute(100);
cmp_ok($sth->rows(), '==', 2, '... got the right number of affected rows');
is($sth->rows(), 2, '... got the right number of affected rows');
};
ok(!$@, '... third state worked as planned');
......@@ -182,10 +182,10 @@ BEGIN {
my $sth = $dbh->prepare('SELECT foo FROM bar WHERE baz = ?');
$sth->execute(100);
my ($result) = $sth->fetchrow_array();
cmp_ok($result, '==', 10, '... first execute got the right value');
is($result, 10, '... first execute got the right value');
$sth->execute(125);
($result) = $sth->fetchrow_array();
cmp_ok($result, '==', 15, '... second execute got the right value');
is($result, 15, '... second execute got the right value');
};
ok(!$@, '... everything worked as planned');
......
......@@ -3,7 +3,7 @@ use 5.006;
use strict;
use warnings;
use Test::More no_plan => 1;
use Test::More tests => 12;
use DBI;
......@@ -17,30 +17,30 @@ $dbh->{mock_start_insert_id} = ['Baz', 345];
my $sth = $dbh->prepare('INSERT INTO Foo (foo, bar) values (?, ?)');
$sth->execute(15, 17);
cmp_ok($dbh->{mock_last_insert_id}, '==', 123, '... got the right insert id');
cmp_ok($dbh->last_insert_id((undef)x4), '==', 123, '... got the right insert id from last_insert_id');
is($dbh->{mock_last_insert_id}, 123, '... got the right insert id');
is($dbh->last_insert_id((undef)x4), 123, '... got the right insert id from last_insert_id');
$sth->execute(16, 18);
cmp_ok($dbh->{mock_last_insert_id}, '==', 124, '... got the right insert id');
cmp_ok($dbh->last_insert_id((undef)x4), '==', 124, '... got the right insert id from last_insert_id');
is($dbh->{mock_last_insert_id}, 124, '... got the right insert id');
is($dbh->last_insert_id((undef)x4), 124, '... got the right insert id from last_insert_id');
$sth->execute(19, 34);
cmp_ok($dbh->{mock_last_insert_id}, '==', 125, '... got the right insert id');
cmp_ok($dbh->last_insert_id((undef)x4), '==', 125, '... got the right insert id from last_insert_id');
is($dbh->{mock_last_insert_id}, 125, '... got the right insert id');
is($dbh->last_insert_id((undef)x4), 125, '... got the right insert id from last_insert_id');
}
{
my $sth = $dbh->prepare('INSERT INTO Baz (foo, bar) values (?, ?)');
$sth->execute(90, 41);
cmp_ok($dbh->{mock_last_insert_id}, '==', 345, '... got the right insert id');
cmp_ok($dbh->last_insert_id((undef)x4), '==', 345, '... got the right insert id from last_insert_id');
is($dbh->{mock_last_insert_id}, 345, '... got the right insert id');
is($dbh->last_insert_id((undef)x4), 345, '... got the right insert id from last_insert_id');
$sth->execute(32, 71);
cmp_ok($dbh->{mock_last_insert_id}, '==', 346, '... got the right insert id');
cmp_ok($dbh->last_insert_id((undef)x4), '==', 346, '... got the right insert id from last_insert_id');
is($dbh->{mock_last_insert_id}, 346, '... got the right insert id');
is($dbh->last_insert_id((undef)x4), 346, '... got the right insert id from last_insert_id');
$sth->execute(77, 42);
cmp_ok($dbh->{mock_last_insert_id}, '==', 347, '... got the right insert id');
cmp_ok($dbh->last_insert_id((undef)x4), '==', 347, '... got the right insert id from last_insert_id');
is($dbh->{mock_last_insert_id}, 347, '... got the right insert id');
is($dbh->last_insert_id((undef)x4), 347, '... got the right insert id from last_insert_id');
}