X-Git-Url: http://git.shadowcat.co.uk/gitweb/gitweb.cgi?a=blobdiff_plain;f=t%2F92storage_on_connect_do.t;h=d132e358bc0d271af93fd58adffb8fb23c21cbcd;hb=ff65e4cab29e1068690f359ea233c76fb1dc7bc7;hp=62712affbab5c41fd2e3dab42cf254d9af088211;hpb=1dafdb2a28c700eabf975685d823036b1b9d69f4;p=dbsrgits%2FDBIx-Class.git diff --git a/t/92storage_on_connect_do.t b/t/92storage_on_connect_do.t index 62712af..d132e35 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 => 9; +use Test::More tests => 12; use lib qw(t/lib); use base 'DBICTest'; @@ -11,6 +11,22 @@ my $schema = DBICTest->init_schema( no_connect => 1, no_deploy => 1, ); + +ok $schema->connection( + DBICTest->_database, + { + on_connect_do => 'CREATE TABLE TEST_empty (id INTEGER)', + }, +), 'connection()'; + +is_deeply ( + $schema->storage->dbh->selectall_arrayref('SELECT * FROM TEST_empty'), + [], + 'string version on_connect_do() worked' +); + +$schema->storage->disconnect; + ok $schema->connection( DBICTest->_database, { @@ -24,20 +40,21 @@ ok $schema->connection( }, ), 'connection()'; -is_deeply +is_deeply ( $schema->storage->dbh->selectall_arrayref('SELECT * FROM TEST_empty'), [ [ 2 ], [ 3 ], [ 7 ] ], - 'on_connect_do() worked'; + '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); +my($connected, $disconnected, @cb_args); ok $schema->connection( DBICTest->_database, { - on_connect_do => sub { $connected = 1 }, + on_connect_do => sub { $connected = 1; @cb_args = @_; }, on_disconnect_do => sub { $disconnected = 1 }, }, ), 'second connection()'; @@ -47,6 +64,7 @@ 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;