Commit | Line | Data |
5fc1107f |
1 | use strict; |
2 | use warnings; |
3 | no warnings qw/once redefine/; |
4 | |
5 | use lib qw(t/lib); |
6 | require DBICTest; |
7 | |
8 | use Test::More tests => 9; |
9 | |
10 | my $schema = DBICTest->init_schema( |
11 | no_connect => 1, |
12 | no_deploy => 1, |
13 | ); |
14 | |
15 | local *DBIx::Class::Storage::DBI::connect_call_foo = sub { |
16 | isa_ok $_[0], 'DBIx::Class::Storage::DBI', |
17 | 'got storage in connect_call method'; |
18 | is $_[1], 'bar', 'got param in connect_call method'; |
19 | }; |
20 | |
21 | local *DBIx::Class::Storage::DBI::disconnect_call_foo = sub { |
22 | isa_ok $_[0], 'DBIx::Class::Storage::DBI', |
23 | 'got storage in disconnect_call method'; |
24 | }; |
25 | |
26 | ok $schema->connection( |
27 | DBICTest->_database, |
28 | { |
29 | on_connect_call => [ |
30 | [ do_sql => 'create table test1 (id integer)' ], |
31 | [ do_sql => [ 'insert into test1 values (?)', {}, 1 ] ], |
32 | [ do_sql => sub { ['insert into test1 values (2)'] } ], |
33 | [ sub { $_[0]->dbh->do($_[1]) }, 'insert into test1 values (3)' ], |
34 | [ foo => 'bar' ], |
35 | ], |
36 | on_connect_do => 'insert into test1 values (4)', |
37 | on_disconnect_call => 'foo', |
38 | }, |
39 | ), 'connection()'; |
40 | |
41 | is_deeply ( |
42 | $schema->storage->dbh->selectall_arrayref('select * from test1'), |
43 | [ [ 1 ], [ 2 ], [ 3 ], [ 4 ] ], |
44 | 'on_connect_call/do actions worked' |
45 | ); |
46 | |
47 | local *DBIx::Class::Storage::DBI::connect_call_foo = sub { |
48 | isa_ok $_[0], 'DBIx::Class::Storage::DBI', |
49 | 'got storage in connect_call method'; |
50 | }; |
51 | |
52 | local *DBIx::Class::Storage::DBI::connect_call_bar = sub { |
53 | isa_ok $_[0], 'DBIx::Class::Storage::DBI', |
54 | 'got storage in connect_call method'; |
55 | }; |
56 | |
57 | $schema->storage->disconnect; |
58 | |
59 | ok $schema->connection( |
60 | DBICTest->_database, |
61 | { |
62 | # method list form |
63 | on_connect_call => [ 'foo', sub { ok 1, "coderef in list form" }, 'bar' ], |
64 | }, |
65 | ), 'connection()'; |
66 | |
67 | $schema->storage->ensure_connected; |