DBIx-Custom / t / mysql2.t /
Newer Older
65 lines | 1.579kb
cleanup
Yuki Kimoto authored on 2011-08-16
1
use Test::More;
2
use strict;
3
use warnings;
4
use utf8;
5

            
6
use FindBin;
7
use DBIx::Custom;
8

            
9
my $dbi;
10
my $dsn;
11
my $args;
12
my $user = 'dbix_custom';
13
my $password = 'dbix_custom';
14
my $database = 'dbix_custom';
15

            
16
$dsn = "dbi:mysql:database=$database";
17
$args = {dsn => $dsn, user => $user, password => $password,};
18

            
19
plan skip_all => 'mysql private test' unless -f "$FindBin::Bin/run/mysql2.run"
20
  && eval { $dbi = DBIx::Custom->connect($args); 1 };
21
plan 'no_plan';
22

            
23
$SIG{__WARN__} = sub { warn $_[0] unless $_[0] =~ /DEPRECATED/};
24

            
25

            
26
require DBIx::Connector;
27

            
28
# Function for test name
29
sub test { print "# $_[0]\n" }
30

            
31
# Varialbes for tests
32
my $dbname;
33
my $rows;
34
my $result;
35

            
36
$dbi = DBIx::Custom->connect(
cleanup
Yuki Kimoto authored on 2012-01-20
37
  dsn => "dbi:mysql:database=$database",
38
  user => $user,
39
  password => $password
cleanup
Yuki Kimoto authored on 2011-08-16
40
);
41
eval { $dbi->execute('drop table table1') };
42
$dbi->execute('create table table1 (key1 varchar(255), key2 varchar(255))');
43

            
44
test 'connector => 1';
45
{
cleanup
Yuki Kimoto authored on 2012-01-20
46
  my $dbi = DBIx::Custom->connect(dsn => $dsn, user => $user, password => $password,
47
    option => {PrintError => 1}, connector => 1);
48
  is(ref $dbi->connector, 'DBIx::Connector');
49
  ok($dbi->dbh->{PrintError});
50
  $dbi->delete_all(table => 'table1');
51
  $dbi->insert(table => 'table1', param => {key1 => 1, key2 => 2});
52
  die "Can't fork" unless defined (my $pid = fork);
cleanup
Yuki Kimoto authored on 2011-08-16
53

            
cleanup
Yuki Kimoto authored on 2012-01-20
54
  if ($pid) {
55
    # Parent
56
    my $result = $dbi->select(table => 'table1');
57
    is_deeply($result->fetch_hash_one, {key1 => 1, key2 => 2});
58
  }
59
  else {
60
    # Child
61
    my $result = $dbi->select(table => 'table1');
62
    die "Not OK" unless $result->fetch_hash_one->{key1} == 1;
63
  }
cleanup
Yuki Kimoto authored on 2011-08-16
64
}
65