File: fetchrow_hashref-many.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 (77 lines) | stat: -rwxr-xr-x 2,169 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
70
71
72
73
74
75
76
77
# $Id: fetchrow_hashref-many.t 236 2008-12-04 10:28:12Z aff $

use strict;				
use warnings;				

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

use Data::Dumper;
use Test::More;
use Test::Warn;

use File::Spec::Functions;
use lib catdir qw ( blib lib );    # use local version of Test::MockDBI
use Test::MockDBI;			

plan tests => 11;

# ------ define variables
my $dbh = "";                                      # mock DBI database handle
my $md  = Test::MockDBI::get_instance();
my $hashref = undef;

# ------ set up return values for DBI fetchrow_hashref() methods
my $arrayref = [
  { key1line1 => 'value1', key2line1 => 'value2' },
  { key1line2 => 'value3', key2line2 => 'value4' },
  { key1line3 => 'value5', key2line3 => 'value6' },
];
$dbh = DBI->connect("", "", "");

warning_like{
  $md->set_retval_scalar(2, "FETCHROW_HASHREF", sub { shift @$arrayref });
} qr/set_retval_scalar is deprecated/, "Legacy warning displayed";

my $sth = $dbh->prepare("FETCHROW_HASHREF");
$sth->execute();

# row 1
$hashref = $sth->fetchrow_hashref();
ok($hashref, q{Expect fetchrow_hashref to return true for first row});
isa_ok($hashref, q{HASH}, q{Expect fetchrow_hashref to return a HASH ref  first row});

is_deeply(
  $hashref,
  { key1line1 => 'value1', key2line1 => 'value2' },
  q{Expect key value pairs line 1}
);

# row 2
$hashref = $sth->fetchrow_hashref();
ok($hashref, q{Expect fetchrow_hashref to return true for second row});
isa_ok($hashref, q{HASH}, q{Expect fetchrow_hashref to return a HASH ref second row});
is_deeply(
  $hashref,
  { key1line2 => 'value3', key2line2 => 'value4' },
  q{Expect key value pairs line 2}
);

# row 3
$hashref = $sth->fetchrow_hashref();
ok($hashref, q{Expect fetchrow_hashref to return true for third row});
isa_ok($hashref, q{HASH}, q{Expect fetchrow_hashref to return a HASH ref second row});
is_deeply(
  $hashref,
  { key1line3 => 'value5', key2line3 => 'value6' },
  q{Expect key value pairs line 3}
);

# row 4 - expected to be undefined
$hashref = $sth->fetchrow_hashref();
ok(!$hashref, q{Expect fetchrow_hashref to return false the fourth time}) or 
	diag(q{rv:}.Dumper($hashref));

__END__