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