3 no warnings qw/once redefine/;
8 use Test::More tests => 9;
10 use DBIx::Class::Storage::DBI;
11 my $schema = DBICTest->init_schema(
16 local *DBIx::Class::Storage::DBI::connect_call_foo = sub {
17 isa_ok $_[0], 'DBIx::Class::Storage::DBI',
18 'got storage in connect_call method';
19 is $_[1], 'bar', 'got param in connect_call method';
22 local *DBIx::Class::Storage::DBI::disconnect_call_foo = sub {
23 isa_ok $_[0], 'DBIx::Class::Storage::DBI',
24 'got storage in disconnect_call method';
27 ok $schema->connection(
31 [ do_sql => 'create table test1 (id integer)' ],
32 [ do_sql => [ 'insert into test1 values (?)', {}, 1 ] ],
33 [ do_sql => sub { ['insert into test1 values (2)'] } ],
34 [ sub { $_[0]->dbh->do($_[1]) }, 'insert into test1 values (3)' ],
35 # this invokes $storage->connect_call_foo('bar') (above)
38 on_connect_do => 'insert into test1 values (4)',
39 on_disconnect_call => 'foo',
44 $schema->storage->dbh->selectall_arrayref('select * from test1'),
45 [ [ 1 ], [ 2 ], [ 3 ], [ 4 ] ],
46 'on_connect_call/do actions worked'
49 local *DBIx::Class::Storage::DBI::connect_call_foo = sub {
50 isa_ok $_[0], 'DBIx::Class::Storage::DBI',
51 'got storage in connect_call method';
54 local *DBIx::Class::Storage::DBI::connect_call_bar = sub {
55 isa_ok $_[0], 'DBIx::Class::Storage::DBI',
56 'got storage in connect_call method';
59 $schema->storage->disconnect;
61 ok $schema->connection(
65 on_connect_call => [ 'foo', sub { ok 1, "coderef in list form" }, 'bar' ],
69 $schema->storage->ensure_connected;