File: 014_st_execute_pass_params.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 (31 lines) | stat: -rw-r--r-- 1,112 bytes parent folder | download | duplicates (5)
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
use strict;

use Test::More tests => 9;

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

my $sql = 'SELECT * FROM foo WHERE bar = ? AND baz = ?';

{
    my $dbh = DBI->connect( 'DBI:Mock:', '', '' );
    my $sth = eval { $dbh->prepare( $sql ) };
    eval { $sth->execute( 'baz', 'bar' ) };
    ok( ! $@, 'Called execute() ok (inline params)' );
    my $t_params = $sth->{mock_my_history}->bound_params;
    is( scalar @{ $t_params }, 2,
        'Correct number of parameters bound (inline; method on tracker)' );
    is( $t_params->[0], 'baz',
        'Statement handle stored bound inline parameter (method on tracker)' );
    is( $t_params->[1], 'bar',
        'Statement handle stored bound inline parameter (method on tracker)' );
    my $a_params = $sth->{mock_my_history}->bound_params;
    is( scalar @{ $a_params }, 2,
        'Correct number of parameters bound (inline; attribute)' );
    is( $a_params->[0], 'baz',
        'Statement handle stored bound inline parameter (attribute)' );
    is( $a_params->[1], 'bar',
        'Statement handle stored bound inline parameter (attribute)' );
}