4 # !!! do not replace this with done_testing - tests reside in the callbacks
5 # !!! number of calls is important
6 use Test::More tests => 12;
15 my $schema = DBICTest->init_schema(
20 ok $schema->connection(
23 on_connect_do => 'CREATE TABLE TEST_empty (id INTEGER)',
28 $schema->storage->dbh->selectall_arrayref('SELECT * FROM TEST_empty'),
30 'string version on_connect_do() worked'
33 $schema->storage->disconnect;
35 ok $schema->connection(
36 sub { DBI->connect(DBICTest->_database) },
39 'CREATE TABLE TEST_empty (id INTEGER)',
40 [ 'INSERT INTO TEST_empty VALUES (?)', {}, 2 ],
44 [\&check_exists, 'DROP TABLE TEST_empty', \&check_dropped],
49 $schema->storage->dbh->selectall_arrayref('SELECT * FROM TEST_empty'),
50 [ [ 2 ], [ 3 ], [ 7 ] ],
51 'on_connect_do() worked'
54 $schema->storage->dbh->do('SELECT 1 FROM TEST_nonexistent');
55 } 'Searching for nonexistent table dies';
57 $schema->storage->disconnect();
59 my($connected, $disconnected, @cb_args);
60 ok $schema->connection(
63 on_connect_do => sub { $connected = 1; @cb_args = @_; },
64 on_disconnect_do => sub { $disconnected = 1 },
66 ), 'second connection()';
67 $schema->storage->dbh->do('SELECT 1');
68 ok $connected, 'on_connect_do() called after connect()';
69 ok ! $disconnected, 'on_disconnect_do() not called after connect()';
70 $schema->storage->disconnect();
71 ok $disconnected, 'on_disconnect_do() called after disconnect()';
73 isa_ok($cb_args[0], 'DBIx::Class::Storage', 'first arg to on_connect_do hook');
77 ok $storage->dbh->do('SELECT 1 FROM TEST_empty'), 'Table still exists';
85 $storage->dbh->do('SELECT 1 FROM TEST_empty');
86 } 'Reading from dropped table fails';
90 sub insert_from_subref {
93 [ 'INSERT INTO TEST_empty VALUES (?)', {}, 3 ],
94 'INSERT INTO TEST_empty VALUES (7)',