1 BEGIN { do "./t/lib/ANFANG.pm" or die ( $@ || $! ) }
6 BEGIN { $ENV{DBICTEST_VIA_REPLICATED} = 0 }
8 # !!! do not replace this with done_testing - tests reside in the callbacks
9 # !!! number of calls is important
10 use Test::More tests => 13;
20 my $schema = DBICTest->init_schema(
25 ok $schema->connection(
28 on_connect_do => 'CREATE TABLE TEST_empty (id INTEGER)',
33 $schema->storage->dbh->selectall_arrayref('SELECT * FROM TEST_empty'),
35 'string version on_connect_do() worked'
38 $schema->storage->disconnect;
40 ok $schema->connection(
41 sub { DBI->connect(DBICTest->_database, undef, undef, { AutoCommit => 0 }) },
43 # DO NOT REMOVE - this seems like an unrelated piece of info,
44 # but is in fact a test for a bug where setting an accessor-via-option
45 # would trigger an early connect *bypassing* the on_connect_* pieces
46 cursor_class => 'DBIx::Class::Storage::Cursor',
49 'CREATE TABLE TEST_empty (id INTEGER)',
50 [ 'INSERT INTO TEST_empty VALUES (?)', {}, 2 ],
54 [\&check_exists, 'DROP TABLE TEST_empty', \&check_dropped],
59 $schema->storage->ensure_connected
60 } qr/The 'RaiseError' of the externally supplied DBI handle is set to false/,
61 'Warning on clobbered AutoCommit => 0 fired';
64 $schema->storage->dbh->selectall_arrayref('SELECT * FROM TEST_empty'),
65 [ [ 2 ], [ 3 ], [ 7 ] ],
66 'on_connect_do() worked'
69 $schema->storage->dbh->do('SELECT 1 FROM TEST_nonexistent');
70 } 'Searching for nonexistent table dies';
72 $schema->storage->disconnect();
74 my($connected, $disconnected, @cb_args);
75 ok $schema->connection(
78 on_connect_do => sub { $connected = 1; @cb_args = @_; },
79 on_disconnect_do => sub { $disconnected = 1 },
81 ), 'second connection()';
82 $schema->storage->dbh->do('SELECT 1');
83 ok $connected, 'on_connect_do() called after connect()';
84 ok ! $disconnected, 'on_disconnect_do() not called after connect()';
85 $schema->storage->disconnect();
86 ok $disconnected, 'on_disconnect_do() called after disconnect()';
88 isa_ok($cb_args[0], 'DBIx::Class::Storage', 'first arg to on_connect_do hook');
93 ok $storage->dbh->do('SELECT 1 FROM TEST_empty'), 'Table still exists';
101 $storage->dbh->do('SELECT 1 FROM TEST_empty');
102 } 'Reading from dropped table fails';
106 sub insert_from_subref {
109 [ 'INSERT INTO TEST_empty VALUES (?)', {}, 3 ],
110 'INSERT INTO TEST_empty VALUES (7)',