force CDBICompat deps for developers, fix tests to work with latest Class::Trigger
[dbsrgits/DBIx-Class.git] / t / 92storage_on_connect_do.t
CommitLineData
579ca3f7 1use strict;
2use warnings;
3
6d2e7a96 4use Test::More tests => 9;
579ca3f7 5
6use lib qw(t/lib);
7use base 'DBICTest';
8
9
10my $schema = DBICTest->init_schema(
11 no_connect => 1,
12 no_deploy => 1,
13);
14ok $schema->connection(
15 DBICTest->_database,
16 {
1bd1640b 17 on_connect_do => [
18 'CREATE TABLE TEST_empty (id INTEGER)',
19 [ 'INSERT INTO TEST_empty VALUES (?)', {}, 2 ],
20 ],
579ca3f7 21 on_disconnect_do =>
22 [\&check_exists, 'DROP TABLE TEST_empty', \&check_dropped],
23 },
24), 'connection()';
25
1bd1640b 26is_deeply
27 $schema->storage->dbh->selectall_arrayref('SELECT * FROM TEST_empty'),
28 [ [ 2 ] ],
29 'on_connect_do() worked';
579ca3f7 30eval { $schema->storage->dbh->do('SELECT 1 FROM TEST_nonexistent'); };
31ok $@, 'Searching for nonexistent table dies';
32
33$schema->storage->disconnect();
34
6d2e7a96 35my($connected, $disconnected);
36ok $schema->connection(
37 DBICTest->_database,
38 {
39 on_connect_do => sub { $connected = 1 },
40 on_disconnect_do => sub { $disconnected = 1 },
41 },
42), 'second connection()';
43$schema->storage->dbh->do('SELECT 1');
44ok $connected, 'on_connect_do() called after connect()';
45ok ! $disconnected, 'on_disconnect_do() not called after connect()';
46$schema->storage->disconnect();
47ok $disconnected, 'on_disconnect_do() called after disconnect()';
48
49
579ca3f7 50sub check_exists {
51 my $storage = shift;
52 ok $storage->dbh->do('SELECT 1 FROM TEST_empty'), 'Table still exists';
53}
54
55sub check_dropped {
56 my $storage = shift;
57 eval { $storage->dbh->do('SELECT 1 FROM TEST_empty'); };
58 ok $@, 'Reading from dropped table fails';
59}