1 BEGIN { do "./t/lib/ANFANG.pm" or die ( $@ || $! ) }
5 no warnings qw/once redefine/;
11 use DBIx::Class::Storage::DBI;
13 # !!! do not replace this with done_testing - tests reside in the callbacks
14 # !!! number of calls is important
15 use Test::More tests => 17;
19 my $schema = DBICTest::Schema->clone;
22 *DBIx::Class::Storage::DBI::connect_call_foo = sub {
23 isa_ok $_[0], 'DBIx::Class::Storage::DBI',
24 'got storage in connect_call method';
25 is $_[1], 'bar', 'got param in connect_call method';
28 *DBIx::Class::Storage::DBI::disconnect_call_foo = sub {
29 isa_ok $_[0], 'DBIx::Class::Storage::DBI',
30 'got storage in disconnect_call method';
33 ok $schema->connection(
37 [ do_sql => 'create table test1 (id integer)' ],
38 [ do_sql => [ 'insert into test1 values (?)', {}, 1 ] ],
39 [ do_sql => sub { ['insert into test1 values (2)'] } ],
40 [ sub { $_[0]->dbh->do($_[1]) }, 'insert into test1 values (3)' ],
41 # this invokes $storage->connect_call_foo('bar') (above)
44 on_connect_do => 'insert into test1 values (4)',
45 on_disconnect_call => 'foo',
49 ok (! $schema->storage->connected, 'start disconnected');
52 $schema->storage->dbh->selectall_arrayref('select * from test1'),
53 [ [ 1 ], [ 2 ], [ 3 ], [ 4 ] ],
54 'on_connect_call/do actions worked'
57 $schema->storage->disconnect;
61 *DBIx::Class::Storage::DBI::connect_call_foo = sub {
62 isa_ok $_[0], 'DBIx::Class::Storage::DBI',
63 'got storage in connect_call method';
66 *DBIx::Class::Storage::DBI::connect_call_bar = sub {
67 isa_ok $_[0], 'DBIx::Class::Storage::DBI',
68 'got storage in connect_call method';
72 ok $schema->connection(
76 on_connect_call => [ 'foo', sub { ok 1, "coderef in list form" }, 'bar' ],
80 ok (! $schema->storage->connected, 'start disconnected');
81 $schema->storage->ensure_connected;
82 $schema->storage->disconnect; # this should not fire any tests
86 ok $schema->connection(
87 sub { DBI->connect(DBICTest->_database, undef, undef, { AutoCommit => 0 } ) },
90 on_connect_call => [ sub { ok 1, "on_connect_call after DT parser" }, ],
91 on_disconnect_call => [ sub { ok 1, "on_disconnect_call after DT parser" }, ],
95 ok (! $schema->storage->connected, 'start disconnected');
97 # this should connect due to the coderef, and also warn due to the false autocommit above
99 $schema->storage->_determine_driver
100 } qr/The 'RaiseError' of the externally supplied DBI handle is set to false/, 'Warning on clobbered AutoCommit => 0 fired';
102 ok ($schema->storage->connected, 'determine driver connects');
103 $schema->storage->disconnect;