Introduce GOVERNANCE document and empty RESOLUTIONS file.
[dbsrgits/DBIx-Class.git] / t / storage / dbh_do.t
CommitLineData
c0329273 1BEGIN { do "./t/lib/ANFANG.pm" or die ( $@ || $! ) }
2
3ff1602f 3use strict;
492bb85a 4use warnings;
3ff1602f 5
492bb85a 6use Test::More;
c0329273 7
3ff1602f 8use DBICTest;
9
10
11my $schema = DBICTest->init_schema();
12my $storage = $schema->storage;
8b60b921 13$storage = $storage->master
de0edd06 14 if $storage->isa('DBIx::Class::Storage::DBI::Replicated');
8b60b921 15
8f6986ac 16# test (re)connection
17for my $disconnect (0, 1) {
18 $schema->storage->_dbh->disconnect if $disconnect;
19 is_deeply (
20 $schema->storage->dbh_do(sub { $_[1]->selectall_arrayref('SELECT 1') }),
21 [ [ 1 ] ],
22 'dbh_do on fresh handle worked',
23 );
24}
25
492bb85a 26my @args;
27my $test_func = sub { @args = @_ };
3ff1602f 28
492bb85a 29$storage->dbh_do($test_func, "foo", "bar");
30is_deeply (
31 \@args,
32 [ $storage, $storage->dbh, "foo", "bar" ],
3ff1602f 33);
34
492bb85a 35
3ff1602f 36my $storage_class = ref $storage;
37{
492bb85a 38 no strict 'refs';
39 local *{$storage_class .'::__test_method'} = $test_func;
40 $storage->dbh_do("__test_method", "baz", "buz");
3ff1602f 41}
3ff1602f 42
492bb85a 43is_deeply (
44 \@args,
45 [ $storage, $storage->dbh, "baz", "buz" ],
46);
47
8f6986ac 48# test nested aliasing
38ed54cd 49my $res = 'original';
b74b15b0 50$schema->storage->dbh_do (sub {
8f6986ac 51 shift->dbh_do(sub { $_[3] = 'changed' }, @_)
52}, $res);
38ed54cd 53
54is ($res, 'changed', "Arguments properly aliased for dbh_do");
55
492bb85a 56done_testing;