Commit | Line | Data |
c0329273 |
1 | BEGIN { do "./t/lib/ANFANG.pm" or die ( $@ || $! ) } |
2 | |
3ff1602f |
3 | use strict; |
492bb85a |
4 | use warnings; |
3ff1602f |
5 | |
492bb85a |
6 | use Test::More; |
c0329273 |
7 | |
3ff1602f |
8 | use DBICTest; |
9 | |
10 | |
11 | my $schema = DBICTest->init_schema(); |
12 | my $storage = $schema->storage; |
13 | |
8b60b921 |
14 | $storage = $storage->master |
15 | if $ENV{DBICTEST_VIA_REPLICATED}; |
16 | |
17 | |
8f6986ac |
18 | # test (re)connection |
19 | for 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 |
28 | my @args; |
29 | my $test_func = sub { @args = @_ }; |
3ff1602f |
30 | |
492bb85a |
31 | $storage->dbh_do($test_func, "foo", "bar"); |
32 | is_deeply ( |
33 | \@args, |
34 | [ $storage, $storage->dbh, "foo", "bar" ], |
3ff1602f |
35 | ); |
36 | |
492bb85a |
37 | |
3ff1602f |
38 | my $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 |
45 | is_deeply ( |
46 | \@args, |
47 | [ $storage, $storage->dbh, "baz", "buz" ], |
48 | ); |
49 | |
8f6986ac |
50 | # test nested aliasing |
38ed54cd |
51 | my $res = 'original'; |
b74b15b0 |
52 | $schema->storage->dbh_do (sub { |
8f6986ac |
53 | shift->dbh_do(sub { $_[3] = 'changed' }, @_) |
54 | }, $res); |
38ed54cd |
55 | |
56 | is ($res, 'changed', "Arguments properly aliased for dbh_do"); |
57 | |
492bb85a |
58 | done_testing; |