Showing 1 changed files with 33 additions and 86 deletions
+33 -86
t/private-mysql.t
... ...
@@ -5,92 +5,39 @@ use warnings;
5 5
 use FindBin;
6 6
 
7 7
 plan skip_all => 'private test' unless -f "$FindBin::Bin/private-mysql-run.tmp";
8
-
9 8
 plan 'no_plan';
10 9
 
11 10
 $SIG{__WARN__} = sub { warn $_[0] unless $_[0] =~ /DEPRECATED/};
12 11
 
13 12
 # user password database
14
-our ($USER, $PASSWORD, $DATABASE) = qw/appuser 123456 usertest/;
13
+our ($user, $password, $database) = qw/appuser 123456 usertest/;
15 14
 
16 15
 require DBIx::Connector;
17 16
 
18 17
 # Function for test name
19 18
 sub test { print "# $_[0]\n" }
20 19
 
21
-# Functions for tests
22
-sub connect_info {
23
-    my $file = 'password.tmp';
24
-    open my $fh, '<', $file
25
-      or return;
26
-    
27
-    my ($user, $password, $database) = split(/\s/, (<$fh>)[0]);
28
-    
29
-    close $fh;
30
-    
31
-    return ($user, $password, $database);
32
-}
33
-
34
-
35 20
 # Varialbes for tests
36 21
 my $dbi;
37 22
 my $dbname;
38 23
 my $rows;
39 24
 my $result;
40 25
 
41
-{
42
-    package DBIx::Custom::MySQL;
43
-
44
-    use strict;
45
-    use warnings;
46
-
47
-    use base 'DBIx::Custom';
48
-
49
-    __PACKAGE__->attr([qw/database host port/]);
50
-
51
-    sub connect {
52
-        my $proto = shift;
53
-        
54
-        # Create a new object
55
-        my $self = ref $proto ? $proto : $proto->new(@_);
56
-        
57
-        # Data source
58
-        if (!$self->dsn) {
59
-            my $database = $self->database;
60
-            my $host     = $self->host;
61
-            my $port     = $self->port;
62
-            my $dsn = "dbi:mysql:";
63
-            $dsn .= "database=$database;" if $database;
64
-            $dsn .= "host=$host;"         if $host;
65
-            $dsn .= "port=$port;"         if $port;
66
-            $self->dsn($dsn);
67
-        }
68
-        
69
-        return $self->SUPER::connect;
70
-    }
71
-
72
-    1;
73
-}
74
-
75 26
 test 'connect';
76
-$dbi = DBIx::Custom::MySQL->new(user => $USER, password => $PASSWORD,
77
-                    database => $DATABASE, host => 'localhost', port => '10000');
78
-$dbi->connect;
79
-like($dbi->dsn, qr/dbi:mysql:database=.*;host=localhost;port=10000;/, "created data source");
80
-is(ref $dbi->dbh, 'DBI::db');
81
-
82
-test 'attributes';
83
-$dbi = DBIx::Custom::MySQL->new;
84
-$dbi->host('a');
85
-is($dbi->host, 'a', "host");
86
-$dbi->port('b');
87
-is($dbi->port, 'b', "port");
27
+eval {
28
+    $dbi = DBIx::Custom->new(
29
+        dsn => "dbi:mysql:database=$database;host=localhost;port=10000",
30
+        user => $user,
31
+        password => $password
32
+    );
33
+};
34
+ok(!$@);
88 35
 
89 36
 test 'limit';
90 37
 $dbi = DBIx::Custom->connect(
91
-    dsn => "dbi:mysql:database=$DATABASE",
92
-    user => $USER,
93
-    password => $PASSWORD
38
+    dsn => "dbi:mysql:database=$database",
39
+    user => $user,
40
+    password => $password
94 41
 );
95 42
 $dbi->delete_all(table => 'table1');
96 43
 $dbi->insert(table => 'table1', param => {key1 => 1, key2 => 2});
... ...
@@ -130,9 +77,9 @@ is_deeply($rows, [{key1 => 1, key2 => 2}]);
130 77
 $dbi->dbh->disconnect;
131 78
 $dbi = undef;
132 79
 $dbi = DBIx::Custom->connect(
133
-    dsn => "dbi:mysql:database=$DATABASE",
134
-    user => $USER,
135
-    password => $PASSWORD
80
+    dsn => "dbi:mysql:database=$database",
81
+    user => $user,
82
+    password => $password
136 83
 );
137 84
 $rows = $dbi->select(
138 85
   table => 'table1',
... ...
@@ -144,9 +91,9 @@ $dbi->delete_all(table => 'table1');
144 91
 
145 92
 test 'type_rule';
146 93
 $dbi = DBIx::Custom->connect(
147
-    dsn => "dbi:mysql:database=$DATABASE",
148
-    user => $USER,
149
-    password => $PASSWORD
94
+    dsn => "dbi:mysql:database=$database",
95
+    user => $user,
96
+    password => $password
150 97
 );
151 98
 eval{$dbi->execute("create table date_test (date DATE, datetime DATETIME)")};
152 99
 $dbi->each_column(
... ...
@@ -201,9 +148,9 @@ $dbi->execute("drop table date_test");
201 148
 test 'dbh';
202 149
 {
203 150
     my $connector = DBIx::Connector->new(
204
-        "dbi:mysql:database=$DATABASE",
205
-        $USER,
206
-        $PASSWORD,
151
+        "dbi:mysql:database=$database",
152
+        $user,
153
+        $password,
207 154
         DBIx::Custom->new->default_dbi_option
208 155
     );
209 156
 
... ...
@@ -221,9 +168,9 @@ test 'transaction';
221 168
 test 'dbh';
222 169
 {
223 170
     my $connector = DBIx::Connector->new(
224
-        "dbi:mysql:database=$DATABASE",
225
-        $USER,
226
-        $PASSWORD,
171
+        "dbi:mysql:database=$database",
172
+        $user,
173
+        $password,
227 174
         DBIx::Custom->new->default_dbi_option
228 175
     );
229 176
 
... ...
@@ -253,9 +200,9 @@ use DBIx::Custom;
253 200
 use Scalar::Util 'blessed';
254 201
 {
255 202
     my $dbi = DBIx::Custom->connect(
256
-        user => $USER,
257
-        password => $PASSWORD,
258
-        dsn => "dbi:mysql:dbname=$DATABASE"
203
+        user => $user,
204
+        password => $password,
205
+        dsn => "dbi:mysql:dbname=$database"
259 206
     );
260 207
     $dbi->connect;
261 208
     
... ...
@@ -267,9 +214,9 @@ use Scalar::Util 'blessed';
267 214
 
268 215
 {
269 216
     my $dbi = DBIx::Custom->connect(
270
-        user => $USER,
271
-        password => $PASSWORD,
272
-        dsn => "dbi:mysql:dbname=$DATABASE",
217
+        user => $user,
218
+        password => $password,
219
+        dsn => "dbi:mysql:dbname=$database",
273 220
         dbi_options => {AutoCommit => 0, mysql_enable_utf8 => 1}
274 221
     );
275 222
     $dbi->connect;
... ...
@@ -280,9 +227,9 @@ use Scalar::Util 'blessed';
280 227
 test 'fork';
281 228
 {
282 229
     my $connector = DBIx::Connector->new(
283
-        "dbi:mysql:database=$DATABASE",
284
-        $USER,
285
-        $PASSWORD,
230
+        "dbi:mysql:database=$database",
231
+        $user,
232
+        $password,
286 233
         DBIx::Custom->new->default_dbi_option
287 234
     );
288 235