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 => 17;
17 my $schema = DBICTest::Schema->clone;
20 *DBIx::Class::Storage::DBI::connect_call_foo = sub {
21 isa_ok $_[0], 'DBIx::Class::Storage::DBI',
22 'got storage in connect_call method';
23 is $_[1], 'bar', 'got param in connect_call method';
26 *DBIx::Class::Storage::DBI::disconnect_call_foo = sub {
27 isa_ok $_[0], 'DBIx::Class::Storage::DBI',
28 'got storage in disconnect_call method';
31 ok $schema->connection(
35 [ do_sql => 'create table test1 (id integer)' ],
36 [ do_sql => [ 'insert into test1 values (?)', {}, 1 ] ],
37 [ do_sql => sub { ['insert into test1 values (2)'] } ],
38 [ sub { $_[0]->dbh->do($_[1]) }, 'insert into test1 values (3)' ],
39 # this invokes $storage->connect_call_foo('bar') (above)
42 on_connect_do => 'insert into test1 values (4)',
43 on_disconnect_call => 'foo',
47 ok (! $schema->storage->connected, 'start disconnected');
50 $schema->storage->dbh->selectall_arrayref('select * from test1'),
51 [ [ 1 ], [ 2 ], [ 3 ], [ 4 ] ],
52 'on_connect_call/do actions worked'
55 $schema->storage->disconnect;
59 *DBIx::Class::Storage::DBI::connect_call_foo = sub {
60 isa_ok $_[0], 'DBIx::Class::Storage::DBI',
61 'got storage in connect_call method';
64 *DBIx::Class::Storage::DBI::connect_call_bar = sub {
65 isa_ok $_[0], 'DBIx::Class::Storage::DBI',
66 'got storage in connect_call method';
70 ok $schema->connection(
74 on_connect_call => [ 'foo', sub { ok 1, "coderef in list form" }, 'bar' ],
78 ok (! $schema->storage->connected, 'start disconnected');
79 $schema->storage->ensure_connected;
80 $schema->storage->disconnect; # this should not fire any tests
84 ok $schema->connection(
85 sub { DBI->connect(DBICTest->_database, undef, undef, { AutoCommit => 0 } ) },
88 on_connect_call => [ sub { ok 1, "on_connect_call after DT parser" }, ],
89 on_disconnect_call => [ sub { ok 1, "on_disconnect_call after DT parser" }, ],
93 ok (! $schema->storage->connected, 'start disconnected');
95 # this should connect due to the coderef, and also warn due to the false autocommit above
97 $schema->storage->_determine_driver
98 } qr/The 'RaiseError' of the externally supplied DBI handle is set to false/, 'Warning on clobbered AutoCommit => 0 fired';
100 ok ($schema->storage->connected, 'determine driver connects');
101 $schema->storage->disconnect;