3 no warnings qw/once redefine/;
9 use DBIx::Class::Storage::DBI;
11 # !!! do not replace this with done_testing - tests reside in the callbacks
12 # !!! number of calls is important
13 use Test::More tests => 15;
16 my $schema = DBICTest::Schema->clone;
19 *DBIx::Class::Storage::DBI::connect_call_foo = sub {
20 isa_ok $_[0], 'DBIx::Class::Storage::DBI',
21 'got storage in connect_call method';
22 is $_[1], 'bar', 'got param in connect_call method';
25 *DBIx::Class::Storage::DBI::disconnect_call_foo = sub {
26 isa_ok $_[0], 'DBIx::Class::Storage::DBI',
27 'got storage in disconnect_call method';
30 ok $schema->connection(
34 [ do_sql => 'create table test1 (id integer)' ],
35 [ do_sql => [ 'insert into test1 values (?)', {}, 1 ] ],
36 [ do_sql => sub { ['insert into test1 values (2)'] } ],
37 [ sub { $_[0]->dbh->do($_[1]) }, 'insert into test1 values (3)' ],
38 # this invokes $storage->connect_call_foo('bar') (above)
41 on_connect_do => 'insert into test1 values (4)',
42 on_disconnect_call => 'foo',
46 ok (! $schema->storage->connected, 'start disconnected');
49 $schema->storage->dbh->selectall_arrayref('select * from test1'),
50 [ [ 1 ], [ 2 ], [ 3 ], [ 4 ] ],
51 'on_connect_call/do actions worked'
54 $schema->storage->disconnect;
58 *DBIx::Class::Storage::DBI::connect_call_foo = sub {
59 isa_ok $_[0], 'DBIx::Class::Storage::DBI',
60 'got storage in connect_call method';
63 *DBIx::Class::Storage::DBI::connect_call_bar = sub {
64 isa_ok $_[0], 'DBIx::Class::Storage::DBI',
65 'got storage in connect_call method';
69 ok $schema->connection(
73 on_connect_call => [ 'foo', sub { ok 1, "coderef in list form" }, 'bar' ],
77 ok (! $schema->storage->connected, 'start disconnected');
78 $schema->storage->ensure_connected;
79 $schema->storage->disconnect; # this should not fire any tests
83 ok $schema->connection(
84 sub { DBI->connect(DBICTest->_database) },
87 on_connect_call => [ sub { ok 1, "on_connect_call after DT parser" }, ],
88 on_disconnect_call => [ sub { ok 1, "on_disconnect_call after DT parser" }, ],
92 ok (! $schema->storage->connected, 'start disconnected');
93 my $parser = $schema->storage->datetime_parser;
95 $schema->storage->ensure_connected;
96 $schema->storage->disconnect;