From: Peter Rabbitson Date: Sat, 3 Oct 2009 13:49:14 +0000 (+0000) Subject: Test reorg (no changes) X-Git-Url: http://git.shadowcat.co.uk/gitweb/gitweb.cgi?a=commitdiff_plain;h=f602cd7bdcd5c981f738a05ade4790110c79c3d2;p=dbsrgits%2FDBIx-Class-Historic.git Test reorg (no changes) --- diff --git a/t/storage/on_connect_call.t b/t/storage/on_connect_call.t index be5e746..880fa3b 100644 --- a/t/storage/on_connect_call.t +++ b/t/storage/on_connect_call.t @@ -3,67 +3,78 @@ use warnings; no warnings qw/once redefine/; use lib qw(t/lib); +use DBI; use DBICTest; +use DBICTest::Schema; +use DBIx::Class::Storage::DBI; -use Test::More tests => 9; +# !!! do not replace this with done_testing - tests reside in the callbacks +# !!! number of calls is important +use Test::More tests => 11; +# !!! -use DBIx::Class::Storage::DBI; -my $schema = DBICTest->init_schema( - no_connect => 1, - no_deploy => 1, -); +my $schema = DBICTest::Schema->clone; + +{ + *DBIx::Class::Storage::DBI::connect_call_foo = sub { + isa_ok $_[0], 'DBIx::Class::Storage::DBI', + 'got storage in connect_call method'; + is $_[1], 'bar', 'got param in connect_call method'; + }; + + *DBIx::Class::Storage::DBI::disconnect_call_foo = sub { + isa_ok $_[0], 'DBIx::Class::Storage::DBI', + 'got storage in disconnect_call method'; + }; -local *DBIx::Class::Storage::DBI::connect_call_foo = sub { - isa_ok $_[0], 'DBIx::Class::Storage::DBI', - 'got storage in connect_call method'; - is $_[1], 'bar', 'got param in connect_call method'; -}; + ok $schema->connection( + DBICTest->_database, + { + on_connect_call => [ + [ do_sql => 'create table test1 (id integer)' ], + [ do_sql => [ 'insert into test1 values (?)', {}, 1 ] ], + [ do_sql => sub { ['insert into test1 values (2)'] } ], + [ sub { $_[0]->dbh->do($_[1]) }, 'insert into test1 values (3)' ], + # this invokes $storage->connect_call_foo('bar') (above) + [ foo => 'bar' ], + ], + on_connect_do => 'insert into test1 values (4)', + on_disconnect_call => 'foo', + }, + ), 'connection()'; -local *DBIx::Class::Storage::DBI::disconnect_call_foo = sub { - isa_ok $_[0], 'DBIx::Class::Storage::DBI', - 'got storage in disconnect_call method'; -}; + ok (! $schema->storage->connected, 'start disconnected'); -ok $schema->connection( - DBICTest->_database, - { - on_connect_call => [ - [ do_sql => 'create table test1 (id integer)' ], - [ do_sql => [ 'insert into test1 values (?)', {}, 1 ] ], - [ do_sql => sub { ['insert into test1 values (2)'] } ], - [ sub { $_[0]->dbh->do($_[1]) }, 'insert into test1 values (3)' ], - # this invokes $storage->connect_call_foo('bar') (above) - [ foo => 'bar' ], - ], - on_connect_do => 'insert into test1 values (4)', - on_disconnect_call => 'foo', - }, -), 'connection()'; + is_deeply ( + $schema->storage->dbh->selectall_arrayref('select * from test1'), + [ [ 1 ], [ 2 ], [ 3 ], [ 4 ] ], + 'on_connect_call/do actions worked' + ); -is_deeply ( - $schema->storage->dbh->selectall_arrayref('select * from test1'), - [ [ 1 ], [ 2 ], [ 3 ], [ 4 ] ], - 'on_connect_call/do actions worked' -); + $schema->storage->disconnect; +} -local *DBIx::Class::Storage::DBI::connect_call_foo = sub { - isa_ok $_[0], 'DBIx::Class::Storage::DBI', - 'got storage in connect_call method'; -}; +{ + *DBIx::Class::Storage::DBI::connect_call_foo = sub { + isa_ok $_[0], 'DBIx::Class::Storage::DBI', + 'got storage in connect_call method'; + }; -local *DBIx::Class::Storage::DBI::connect_call_bar = sub { - isa_ok $_[0], 'DBIx::Class::Storage::DBI', - 'got storage in connect_call method'; -}; + *DBIx::Class::Storage::DBI::connect_call_bar = sub { + isa_ok $_[0], 'DBIx::Class::Storage::DBI', + 'got storage in connect_call method'; + }; -$schema->storage->disconnect; -ok $schema->connection( - DBICTest->_database, - { - # method list form - on_connect_call => [ 'foo', sub { ok 1, "coderef in list form" }, 'bar' ], - }, -), 'connection()'; + ok $schema->connection( + DBICTest->_database, + { + # method list form + on_connect_call => [ 'foo', sub { ok 1, "coderef in list form" }, 'bar' ], + }, + ), 'connection()'; -$schema->storage->ensure_connected; + ok (! $schema->storage->connected, 'start disconnected'); + $schema->storage->ensure_connected; + $schema->storage->disconnect; # this should not fire any tests +}