(travis) Temporary pin LMU, work around RT#102853
[dbsrgits/DBIx-Class.git] / t / storage / dbh_do.t
CommitLineData
3ff1602f 1use strict;
492bb85a 2use warnings;
3ff1602f 3
492bb85a 4use Test::More;
3ff1602f 5use lib qw(t/lib);
6use DBICTest;
7
8
9my $schema = DBICTest->init_schema();
10my $storage = $schema->storage;
11
8f6986ac 12# test (re)connection
13for my $disconnect (0, 1) {
14 $schema->storage->_dbh->disconnect if $disconnect;
15 is_deeply (
16 $schema->storage->dbh_do(sub { $_[1]->selectall_arrayref('SELECT 1') }),
17 [ [ 1 ] ],
18 'dbh_do on fresh handle worked',
19 );
20}
21
492bb85a 22my @args;
23my $test_func = sub { @args = @_ };
3ff1602f 24
492bb85a 25$storage->dbh_do($test_func, "foo", "bar");
26is_deeply (
27 \@args,
28 [ $storage, $storage->dbh, "foo", "bar" ],
3ff1602f 29);
30
492bb85a 31
3ff1602f 32my $storage_class = ref $storage;
33{
492bb85a 34 no strict 'refs';
35 local *{$storage_class .'::__test_method'} = $test_func;
36 $storage->dbh_do("__test_method", "baz", "buz");
3ff1602f 37}
3ff1602f 38
492bb85a 39is_deeply (
40 \@args,
41 [ $storage, $storage->dbh, "baz", "buz" ],
42);
43
8f6986ac 44# test nested aliasing
38ed54cd 45my $res = 'original';
8f6986ac 46$storage->dbh_do (sub {
47 shift->dbh_do(sub { $_[3] = 'changed' }, @_)
48}, $res);
38ed54cd 49
50is ($res, 'changed', "Arguments properly aliased for dbh_do");
51
492bb85a 52done_testing;