| 1 |
use 5.008; |
| 2 |
|
| 3 |
use strict; |
| 4 |
use warnings; |
| 5 |
|
| 6 |
use Test::More; |
| 7 |
|
| 8 |
BEGIN { |
| 9 |
use_ok('DBD::Mock'); |
| 10 |
use_ok('DBI'); |
| 11 |
} |
| 12 |
|
| 13 |
my $dbh = DBI->connect('dbi:Mock:', '', ''); |
| 14 |
isa_ok($dbh, 'DBI::db'); |
| 15 |
|
| 16 |
foreach my $i ( 1 .. 2 ) { |
| 17 |
my $sth = $dbh->prepare('SELECT foo FROM bar WHERE x = ?'); |
| 18 |
$sth->execute($i); |
| 19 |
my $history = $dbh->{mock_all_history}; |
| 20 |
is(scalar(@{$history}), $i, "... have $i statement executions"); |
| 21 |
} |
| 22 |
|
| 23 |
$dbh->{mock_clear_history} = 1; |
| 24 |
my $history = $dbh->{mock_all_history}; |
| 25 |
is(scalar(@{$history}), 0, '... the history has been is cleared'); |
| 26 |
|
| 27 |
foreach my $i ( 1 .. 2 ) { |
| 28 |
my $sth = $dbh->prepare_cached('SELECT foo FROM bar WHERE x = ?'); |
| 29 |
$sth->execute($i); |
| 30 |
my $history = $dbh->{mock_all_history}; |
| 31 |
is(scalar(@{$history}), $i, "... have $i statement executions"); |
| 32 |
} |
| 33 |
|
| 34 |
my $st_track = $dbh->{mock_all_history}->[0]; |
| 35 |
isa_ok($st_track, 'DBD::Mock::StatementTrack'); |
| 36 |
|
| 37 |
is($st_track->statement, 'SELECT foo FROM bar WHERE x = ?', '... our statements match'); |
| 38 |
|
| 39 |
my $params = $st_track->bound_params; |
| 40 |
is(scalar(@{$params}), 1, '... got the expected amount of params'); |
| 41 |
|
| 42 |
done_testing(); |