File: 001_db_handle.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 (132 lines) | stat: -rw-r--r-- 3,734 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
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
use strict;

use Test::More tests => 24;

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

# test misc. attributes

{
    my $dbh = DBI->connect('DBI:Mock:', 'user', 'pass');
    isa_ok($dbh, 'DBI::db'); 
    
    is($dbh->{Name}, '', '... if no db-name is given');
    ok( $dbh->{AutoCommit},
        '... AutoCommit DB attribute defaults to set' );    
    
    # DBI will handle attributes with 'private_', 'dbi_' or ,
    # 'dbd_' prefixes but all others, we need to handle.
    
    $dbh->{mysql_insertid} = 10;
    is($dbh->{mysql_insertid}, 10, '... this attribute should be 10');
    
    # DBI will handle these
    
    $dbh->{private_insert_id} = 15;
    is($dbh->{private_insert_id}, 15, '... this attribute should be 15');    
    
    $dbh->{dbi_attribute} = 2000;
    is($dbh->{dbi_attribute}, 2000, '... this attribute should be 2000');  
    
    $dbh->{dbd_attr} = 15_000;
    is($dbh->{dbd_attr}, 15_000, '... this attribute should be 15,000');  
    
    $dbh->disconnect();     
}   

# test setting attributes post-connect

{
    
    my $dbh = DBI->connect( 'DBI:Mock:', '', '' );
    $dbh->{RaiseError} = 1;
    $dbh->{PrintError} = 1;
    $dbh->{AutoCommit} = 1;
   
    ok( $dbh->{RaiseError},
        'RaiseError DB attribute set after connect()' );
    ok( $dbh->{PrintError},
        'PrintError DB attribute set after connect()' );
    ok( $dbh->{AutoCommit},
        'AutoCommit DB attribute set after connect()' );
            
    $dbh->disconnect();       
}

# test setting them during connect

{
    my $dbh = DBI->connect( 'DBI:Mock:', '', '',
                            { RaiseError => 1,
                              PrintError => 1,
                              AutoCommit => 1 } );
    ok( $dbh->{RaiseError},
        'RaiseError DB attribute set in connect()' );
    ok( $dbh->{PrintError},
        'PrintError DB attribute set in connect()' );
    ok( $dbh->{AutoCommit},
        'AutoCommit DB attribute set in connect()' );

    $dbh->disconnect();   
}

# test setting attributes with false values during connect

{
    my $dbh = DBI->connect( 'DBI:Mock:', '', '',
                            { RaiseError => 0,
                              PrintError => 0,
                              AutoCommit => 0 } );
    ok( ! $dbh->{RaiseError},
        'RaiseError DB attribute unset in connect()' );
    ok( ! $dbh->{PrintError},
        'PrintError DB attribute unset in connect()' );
    ok( ! $dbh->{AutoCommit},
        'AutoCommit DB attribute unset in connect()' );

    $dbh->disconnect();   
}


{
    my $dbh = DBI->connect( 'DBI:Mock:', '', '' );
    is_deeply(
        [ $dbh->data_sources() ],
        [ 'DBI:Mock:' ],
        '... got the right data sources');
        
    $dbh->{'mock_add_data_sources'} = 'foo';
    
    is_deeply(
        [ $dbh->data_sources() ],
        [ 'DBI:Mock:', 'DBI:Mock:foo' ],
        '... got the right data sources');

}

{
    my $dbh = DBI->connect( 'DBI:Mock:', '', '',
                            { RaiseError => 0,
                              PrintError => 0,
                              PrintWarn  => 0,
                              AutoCommit => 0,
                            } );
    $dbh->{RaiseError} = 1;
    $dbh->{PrintError} = 1;
    $dbh->{PrintWarn}  = 1;
    $dbh->{AutoCommit} = 1;

    ok( $dbh->{RaiseError},
        'RaiseError DB attribute set in connect() and then changed' );
    ok( $dbh->{PrintError},
        'PrintError DB attribute set in connect() and then changed' );
    ok( $dbh->{PrintWarn},
        'PrintWarn DB attribute set in connect() and then changed' );
    ok( $dbh->{AutoCommit},
        'AutoCommit DB attribute set in connect() and then changed' );

    $dbh->disconnect();   
}