Institute a central "load this first in testing" package
[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;
13
8b60b921 14$storage = $storage->master
15 if $ENV{DBICTEST_VIA_REPLICATED};
16
17
8f6986ac 18# test (re)connection
19for my $disconnect (0, 1) {
20 $schema->storage->_dbh->disconnect if $disconnect;
21 is_deeply (
22 $schema->storage->dbh_do(sub { $_[1]->selectall_arrayref('SELECT 1') }),
23 [ [ 1 ] ],
24 'dbh_do on fresh handle worked',
25 );
26}
27
492bb85a 28my @args;
29my $test_func = sub { @args = @_ };
3ff1602f 30
492bb85a 31$storage->dbh_do($test_func, "foo", "bar");
32is_deeply (
33 \@args,
34 [ $storage, $storage->dbh, "foo", "bar" ],
3ff1602f 35);
36
492bb85a 37
3ff1602f 38my $storage_class = ref $storage;
39{
492bb85a 40 no strict 'refs';
41 local *{$storage_class .'::__test_method'} = $test_func;
42 $storage->dbh_do("__test_method", "baz", "buz");
3ff1602f 43}
3ff1602f 44
492bb85a 45is_deeply (
46 \@args,
47 [ $storage, $storage->dbh, "baz", "buz" ],
48);
49
8f6986ac 50# test nested aliasing
38ed54cd 51my $res = 'original';
b74b15b0 52$schema->storage->dbh_do (sub {
8f6986ac 53 shift->dbh_do(sub { $_[3] = 'changed' }, @_)
54}, $res);
38ed54cd 55
56is ($res, 'changed', "Arguments properly aliased for dbh_do");
57
492bb85a 58done_testing;