File: 011_st_execute_empty.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 (41 lines) | stat: -rw-r--r-- 1,415 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
32
33
34
35
36
37
38
39
40
41
use strict;

use Test::More tests => 15;

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 ) };
    ok( ! $@, 'Statement handle prepared ok' );
    is( ref( $sth ), 'DBI::st',
        'Statement handle returned of the proper type' );
    is( $sth->{mock_my_history}->statement, $sql,
        'Statement handle stores SQL (method on tracker)' );
    is( $sth->{mock_statement}, $sql,
        'Statement handle stores SQL (attribute)' );
    is( $sth->{mock_is_executed}, 'no',
        'Execute flag not set yet' );
    my $rows = eval { $sth->execute() };
    ok( ! $@, 'Called execute() ok (no params)' );
    is($rows, '0E0', '... we got back 0E0 for num of rows');
    is( $sth->{mock_is_executed}, 'yes',
        'Execute flag set after execute()' );
    my $t_params = $sth->{mock_my_history}->bound_params;
    is( scalar @{ $t_params }, 0,
        'No parameters tracked (method on tracker)' );
    my $a_params = $sth->{mock_params};
    is( scalar @{ $a_params }, 0,
        'No parameters tracked (attribute)' );
    is( $sth->{mock_is_finished}, 'no',
        'Finished flag not set yet' );
    eval { $sth->finish };
    ok( ! $@, 'Called finish() ok' );
    is( $sth->{mock_is_finished}, 'yes',
        'Finished flag set after finish()' );
}