4 # !!! do not replace this with done_testing - tests reside in the callbacks
5 # !!! number of calls is important
6 use Test::More tests => 13;
16 my $schema = DBICTest->init_schema(
21 ok $schema->connection(
24 on_connect_do => 'CREATE TABLE TEST_empty (id INTEGER)',
29 $schema->storage->dbh->selectall_arrayref('SELECT * FROM TEST_empty'),
31 'string version on_connect_do() worked'
34 $schema->storage->disconnect;
36 ok $schema->connection(
37 sub { DBI->connect(DBICTest->_database, undef, undef, { AutoCommit => 0 }) },
40 'CREATE TABLE TEST_empty (id INTEGER)',
41 [ 'INSERT INTO TEST_empty VALUES (?)', {}, 2 ],
45 [\&check_exists, 'DROP TABLE TEST_empty', \&check_dropped],
50 $schema->storage->ensure_connected
51 } qr/The 'RaiseError' of the externally supplied DBI handle is set to false/,
52 'Warning on clobbered AutoCommit => 0 fired';
55 $schema->storage->dbh->selectall_arrayref('SELECT * FROM TEST_empty'),
56 [ [ 2 ], [ 3 ], [ 7 ] ],
57 'on_connect_do() worked'
60 $schema->storage->dbh->do('SELECT 1 FROM TEST_nonexistent');
61 } 'Searching for nonexistent table dies';
63 $schema->storage->disconnect();
65 my($connected, $disconnected, @cb_args);
66 ok $schema->connection(
69 on_connect_do => sub { $connected = 1; @cb_args = @_; },
70 on_disconnect_do => sub { $disconnected = 1 },
72 ), 'second connection()';
73 $schema->storage->dbh->do('SELECT 1');
74 ok $connected, 'on_connect_do() called after connect()';
75 ok ! $disconnected, 'on_disconnect_do() not called after connect()';
76 $schema->storage->disconnect();
77 ok $disconnected, 'on_disconnect_do() called after disconnect()';
79 isa_ok($cb_args[0], 'DBIx::Class::Storage', 'first arg to on_connect_do hook');
84 ok $storage->dbh->do('SELECT 1 FROM TEST_empty'), 'Table still exists';
92 $storage->dbh->do('SELECT 1 FROM TEST_empty');
93 } 'Reading from dropped table fails';
97 sub insert_from_subref {
100 [ 'INSERT INTO TEST_empty VALUES (?)', {}, 3 ],
101 'INSERT INTO TEST_empty VALUES (7)',