File: 006_prepare_cached.t

package info (click to toggle)
libdbd-mock-perl 1.43-1
  • links: PTS, VCS
  • area: main
  • in suites: wheezy
  • size: 416 kB
  • sloc: perl: 1,135; makefile: 2
file content (37 lines) | stat: -rw-r--r-- 1,070 bytes parent folder | download | duplicates (4)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
use strict;

use Test::More tests => 11;

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

my $dbh = DBI->connect('dbi:Mock:', '', '');
isa_ok($dbh, 'DBI::db');

foreach my $i ( 1 .. 2 ) {
    my $sth = $dbh->prepare('SELECT foo FROM bar WHERE x = ?');
    $sth->execute($i);
    my $history = $dbh->{mock_all_history};
    is(scalar(@{$history}), $i, "... have $i statement executions");
}

$dbh->{mock_clear_history} = 1;
my $history = $dbh->{mock_all_history};
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};
    is(scalar(@{$history}), $i, "... have $i statement executions");
}

my $st_track = $dbh->{mock_all_history}->[0];
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;
is(scalar(@{$params}), 1, '... got the expected amount of params');