##########
FILES
##########
./t/mock_db_test.t
./t/sample_db_data_test.pm
####
##############
Test execution
##############
$ prove -v t/mock_db_test.t
t/mock_db_test....ok 1 - baseline test
# $VAR1 = [
# 1,
# 'name1',
# 'description1',
# 'created_on1',
# 'created_by1',
# 'deleted1',
# 'deleted_by1',
# 'public1'
# ];
1..1
ok
All tests successful.
Files=1, Tests=1, 0 wallclock secs ( 0.03 cusr + 0.01 csys = 0.04 CPU)
$
####
##################
./t/mock_db_test.t
##################
use Test::More qw(no_plan);
use strict;
use warnings;
### Just a blank test so this sample runs.
ok(1,'baseline test');
### Load DBI and create a handle.
use DBI;
my $dbh = DBI->connect('DBI:Mock:', '', '');
### Load the sample data set into memory and add it as a resultset to the
### mock db driver.
use t::sample_db_data_test;
$dbh->{'mock_add_resultset'} = \@t::sample_db_data_test::Accounts;
### Try to get just the name and description.
my $sth = $dbh->prepare('SELECT name, description FROM Accounts WHERE id=?');
if ($sth->execute(3)) {
### Successful query.
my @results = $sth->fetchrow_array;
use Data::Dumper;
diag(Dumper(\@results));
} else {
### Failure...
diag('Some weird error: ' . $sth->errstr);
}
####
##########################
./t/sample_db_data_test.pm
##########################
package t::sample_db_data_test;
our @Accounts = (
['id', 'name', 'description', 'created_on', 'created_by','deleted', 'deleted_by', 'public'],
[ 1, 'name1','description1','created_on1','created_by1','deleted1','deleted_by1','public1'],
[ 2, 'name2','description2','created_on2','created_by2','deleted2','deleted_by2','public2'],
[ 3, 'name3','description3','created_on3','created_by3','deleted3','deleted_by3','public3'],
);
1;