Debian Codegraph @

t/019_mock_statement_track_iterator.t

raw
1 use 5.008;
2
3 use strict;
4 use warnings;
5
6 use Test::More;
7
8 BEGIN {
9 use_ok('DBD::Mock');
10 }
11
12 # just test the iterator plain
13 {
14 my $i = DBD::Mock::StatementTrack::Iterator->new([ 1 .. 5 ]);
15 isa_ok($i, 'DBD::Mock::StatementTrack::Iterator');
16
17 is($i->next(), 1, '... got 1');
18 is($i->next(), 2, '... got 2');
19 is($i->next(), 3, '... got 3');
20 is($i->next(), 4, '... got 4');
21 is($i->next(), 5, '... got 5');
22 ok(!defined($i->next()), '... got undef');
23
24 $i->reset();
25
26 is($i->next(), 1, '... got 1');
27 is($i->next(), 2, '... got 2');
28 is($i->next(), 3, '... got 3');
29 is($i->next(), 4, '... got 4');
30 is($i->next(), 5, '... got 5');
31 ok(!defined($i->next()), '... got undef');
32 }
33
34 # and now test it within context
35
36 my $dbh = DBI->connect('DBI:Mock:', '', '');
37 isa_ok($dbh, 'DBI::db');
38
39 my $i = $dbh->{mock_all_history_iterator};
40 isa_ok($i, 'DBD::Mock::StatementTrack::Iterator');
41
42 ok(!defined($i->next()), '... nothing in the iterator');
43
44 $dbh->prepare("INSERT INTO nothing (nothing) VALUES('nada')");
45
46 ok(defined($i->next()), '... now something in the iterator (which is what we want)');
47
48 $dbh->prepare("INSERT INTO nothing (nothing) VALUES('nada')");
49
50 my $next = $i->next();
51 ok(defined($next), '... something in the iterator');
52 isa_ok($next, 'DBD::Mock::StatementTrack');
53 is($next->statement, "INSERT INTO nothing (nothing) VALUES('nada')", '... its our old insert statement too');
54
55 ok(!defined($i->next()), '... now nothing in the iterator');
56
57 done_testing();