Commit | Line | Data |
5fc1107f |
1 | use strict; |
2 | use warnings; |
3 | no warnings qw/once redefine/; |
4 | |
5 | use lib qw(t/lib); |
9900b569 |
6 | use DBICTest; |
5fc1107f |
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)' ], |
9900b569 |
34 | # this invokes $storage->connect_call_foo('bar') (above) |
5fc1107f |
35 | [ foo => 'bar' ], |
36 | ], |
37 | on_connect_do => 'insert into test1 values (4)', |
38 | on_disconnect_call => 'foo', |
39 | }, |
40 | ), 'connection()'; |
41 | |
42 | is_deeply ( |
43 | $schema->storage->dbh->selectall_arrayref('select * from test1'), |
44 | [ [ 1 ], [ 2 ], [ 3 ], [ 4 ] ], |
45 | 'on_connect_call/do actions worked' |
46 | ); |
47 | |
48 | local *DBIx::Class::Storage::DBI::connect_call_foo = sub { |
49 | isa_ok $_[0], 'DBIx::Class::Storage::DBI', |
50 | 'got storage in connect_call method'; |
51 | }; |
52 | |
53 | local *DBIx::Class::Storage::DBI::connect_call_bar = sub { |
54 | isa_ok $_[0], 'DBIx::Class::Storage::DBI', |
55 | 'got storage in connect_call method'; |
56 | }; |
57 | |
58 | $schema->storage->disconnect; |
59 | |
60 | ok $schema->connection( |
61 | DBICTest->_database, |
62 | { |
63 | # method list form |
64 | on_connect_call => [ 'foo', sub { ok 1, "coderef in list form" }, 'bar' ], |
65 | }, |
66 | ), 'connection()'; |
67 | |
68 | $schema->storage->ensure_connected; |