3 no warnings qw/once redefine/;
8 use Test::More tests => 9;
10 my $schema = DBICTest->init_schema(
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';
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';
26 ok $schema->connection(
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 # this invokes $storage->connect_call_foo('bar') (above)
37 on_connect_do => 'insert into test1 values (4)',
38 on_disconnect_call => 'foo',
43 $schema->storage->dbh->selectall_arrayref('select * from test1'),
44 [ [ 1 ], [ 2 ], [ 3 ], [ 4 ] ],
45 'on_connect_call/do actions worked'
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';
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';
58 $schema->storage->disconnect;
60 ok $schema->connection(
64 on_connect_call => [ 'foo', sub { ok 1, "coderef in list form" }, 'bar' ],
68 $schema->storage->ensure_connected;