X-Git-Url: http://git.shadowcat.co.uk/gitweb/gitweb.cgi?a=blobdiff_plain;f=t%2F92storage_on_connect_do.t;h=6c467cd54c9b8e939987eb18890dfd4d8b11ab54;hb=f623c6ee5de411b8a231abf80f65b33a117878a3;hp=038e4d7272611608d6fb51a7f0268c55a3a9113a;hpb=579ca3f74419c0167a4659d5df9e875cd47ba3b7;p=dbsrgits%2FDBIx-Class.git diff --git a/t/92storage_on_connect_do.t b/t/92storage_on_connect_do.t index 038e4d7..6c467cd 100644 --- a/t/92storage_on_connect_do.t +++ b/t/92storage_on_connect_do.t @@ -1,7 +1,7 @@ use strict; use warnings; -use Test::More tests => 5; +use Test::More tests => 10; use lib qw(t/lib); use base 'DBICTest'; @@ -14,25 +14,58 @@ my $schema = DBICTest->init_schema( ok $schema->connection( DBICTest->_database, { - on_connect_do => ['CREATE TABLE TEST_empty (id INTEGER)'], + on_connect_do => [ + 'CREATE TABLE TEST_empty (id INTEGER)', + [ 'INSERT INTO TEST_empty VALUES (?)', {}, 2 ], + \&insert_from_subref, + ], on_disconnect_do => [\&check_exists, 'DROP TABLE TEST_empty', \&check_dropped], }, ), 'connection()'; -ok $schema->storage->dbh->do('SELECT 1 FROM TEST_empty'), 'on_connect_do() worked'; +is_deeply + $schema->storage->dbh->selectall_arrayref('SELECT * FROM TEST_empty'), + [ [ 2 ], [ 3 ], [ 7 ] ], + 'on_connect_do() worked'; eval { $schema->storage->dbh->do('SELECT 1 FROM TEST_nonexistent'); }; ok $@, 'Searching for nonexistent table dies'; $schema->storage->disconnect(); +my($connected, $disconnected, @cb_args); +ok $schema->connection( + DBICTest->_database, + { + on_connect_do => sub { $connected = 1; @cb_args = @_; }, + on_disconnect_do => sub { $disconnected = 1 }, + }, +), 'second connection()'; +$schema->storage->dbh->do('SELECT 1'); +ok $connected, 'on_connect_do() called after connect()'; +ok ! $disconnected, 'on_disconnect_do() not called after connect()'; +$schema->storage->disconnect(); +ok $disconnected, 'on_disconnect_do() called after disconnect()'; + +isa_ok($cb_args[0], 'DBIx::Class::Storage', 'first arg to on_connect_do hook'); + sub check_exists { my $storage = shift; ok $storage->dbh->do('SELECT 1 FROM TEST_empty'), 'Table still exists'; + return; } sub check_dropped { my $storage = shift; eval { $storage->dbh->do('SELECT 1 FROM TEST_empty'); }; ok $@, 'Reading from dropped table fails'; + return; +} + +sub insert_from_subref { + my $storage = shift; + return [ + [ 'INSERT INTO TEST_empty VALUES (?)', {}, 3 ], + 'INSERT INTO TEST_empty VALUES (7)', + ]; }