File: fetchrow_arrayref-different-sql.t

package info (click to toggle)
libtest-mockdbi-perl 0.70-3
  • links: PTS, VCS
  • area: main
  • in suites: bookworm, forky, sid, trixie
  • size: 372 kB
  • sloc: perl: 954; makefile: 2
file content (69 lines) | stat: -rwxr-xr-x 2,190 bytes parent folder | download | duplicates (3)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
# Test::MockDBI fetch*() which return an array handle multiple SQL statements.

# $Id: fetchrow_arrayref-different-sql.t 246 2008-12-04 13:01:22Z aff $

# ------ enable testing mock DBI
BEGIN { push @ARGV, "--dbitest=2"; }

# ------ use/require pragmas
use strict;            # better compile-time checking
use warnings;          # better run-time checking

use Test::More;
use Test::Warn;

plan tests => 7;

use File::Spec::Functions;
use lib catdir qw ( blib lib );    # use local module
use Test::MockDBI;     # what we are testing

# ------ define variables
my $dbh = "";          # mock DBI database handle
my $md = Test::MockDBI::get_instance();
my $retval = "";			# return value from fetchrow_arrayref()


# ------ set up return values for DBI fetch*() methods
$dbh = DBI->connect("", "", "");

warning_like{
  $md->set_retval_scalar(2, "FETCHROW_ARRAYREF",                  [ "go deep", 476 ]);
} qr/set_retval_scalar is deprecated/, "Legacy warning displayed";

warning_like{
  $md->set_retval_scalar(2, "SELECT zip5_zipcode.+'Chino Hills'", [ "Experian stuff", 1492 ]);
} qr/set_retval_scalar is deprecated/, "Legacy warning displayed";

# test non-matching sql
my $sth = $dbh->prepare("other SQL");
$sth->execute();
ok(!defined($sth->fetchrow_arrayref()), q{Expect undef on non-matching sql});
$sth->finish();

# test matching sql
$sth = $dbh->prepare("FETCHROW_ARRAYREF");
$sth->execute();
$retval = $sth->fetchrow_arrayref();
is_deeply($retval, [ "go deep", 476 ], q{Expect array ref [ "go deep", 476 ]});
$sth->finish();

# test non-matching sql again
$sth = $dbh->prepare("STILL oTheR SQL");
$sth->execute();
ok(!defined($sth->fetchrow_arrayref()), q{Expect undef on another non-matching sql});
$sth->finish();

# test another matching sql
$sth = $dbh->prepare("SELECT zip5_zipcode FROM ziplist5 WHERE zip5_cityname = 'Chino Hills'");
$sth->execute();
$retval = $sth->fetchrow_arrayref();
is_deeply($retval, ["Experian stuff", 1492], q{Expect array ("Experian stuff", 1492)});
$sth->finish();

# test non-matching sql third time
$sth = $dbh->prepare("LaSt sqL");
$sth->execute();
ok(!defined($sth->fetchrow_arrayref()), q{Expect undef on another non-matching sql});

__END__