Run the entire test suite under replicated SQLite on DBICTEST_VIA_REPLICATED
[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
fd2c6658 12$storage = $storage->master
13 if $ENV{DBICTEST_VIA_REPLICATED};
14
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';
a6543cfa 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;