blib/lib/DBIO/Test/Schema.pm

filter: Statementstmt 67.6% 48 / 71 Branchbran 27.7% 5 / 18 Conditioncond 17.2% 5 / 29 MC/DCmcdc 6.2% 1 / 16 Subroutinesub 83.3% 10 / 12 Podpod 100% 4 / 4 totaltotal 48.6% 73 / 150 CC 23 SCAR 46.8
CC
23
Cov
49%
is_executed_sql_bind
240.0
is_executed_querycount
6.2
capture_executed_sql_bind
4.0
CRAP 107.8
« blib/lib/DBIO/Test/Util/LeakTracer.pm ↑ Summary blib/lib/DBIO/SQL/Util.pm »
1 package DBIO::Test::Schema;
2 # ABSTRACT: Standard test schema for the DBIO ecosystem
3  
4 256 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
5 256 ▶use warnings;
Subroutine BEGIN: called CC=1 SCAR=0.0
6  
7 256 our $VERSION = '0.900007';
8  
9 256 ▶no warnings 'qw';
Subroutine BEGIN: called CC=1 SCAR=0.0
10  
11 256 ▶use base 'DBIO::Schema';
Subroutine BEGIN: called CC=1 SCAR=0.0
12 256 ▶use DBIO::Util qw(old_mro);
Subroutine BEGIN: called CC=1 SCAR=0.0
13 256 ▶use namespace::clean;
Subroutine BEGIN: called CC=1 SCAR=0.0
14  
15  
16 256 __PACKAGE__->mk_group_accessors(simple => 'custom_attr');
17  
18 256 __PACKAGE__->load_classes(qw/
19 Artist
20 ArtistGUID
21 BindType
22 Employee
23 CD
24 Genre
25 Bookmark
26 Link
27 #dummy
28 Track
29 Tag
30 Year2000CDs
31 Year1999CDs
32 CustomSql
33 TimestampPrimaryKey
34 /,
35 { 'DBIO::Test::Schema' => [qw/
36 LinerNotes
37 Artwork
38 Artwork_to_Artist
39 Image
40 Lyrics
41 LyricVersion
42 OneKey
43 #dummy
44 TwoKeys
45 Serialized
46 /]},
47 (
48 'FourKeys',
49 'FourKeys_to_TwoKeys',
50 '#dummy',
51 'SelfRef',
52 'ArtistUndirectedMap',
53 'ArtistSourceName',
54 'ArtistSubclass',
55 'Producer',
56 'CD_to_Producer',
57 'Dummy', # this is a real result class we remove in the hook below
58 ),
59 qw/SelfRefAlias TreeLike TwoKeyTreeLike Event NoPrimaryKey/,
60 qw/Collection CollectionObject TypedObject Owners BooksInLibrary/,
61 qw/ForceForeign Encoded Money/,
62 );
63  
64 0 ▶sub sqlt_deploy_hook {
Subroutine sqlt_deploy_hook: not called CC=1 SCAR=6.9
Pod documented
65 0 my ($self, $sqlt_schema) = @_;
66  
67 0 $sqlt_schema->drop_table('dummy');
68 }
69  
70  
71 12 ▶sub capture_executed_sql_bind {
Subroutine capture_executed_sql_bind: called CC=4 SCAR=13.9
Pod documented
72 12 my ($self, $cref) = @_;
73  
74 12 ▶ $self->throw_exception("Expecting a coderef to run") unless ref $cref eq 'CODE';
Branch: 1 branch
BranchTrueFalseTotal
unless ref $cref eq "CODE" 0 12 12
75  
76 12 require DBIO::Test::SQLTracerObj;
77  
78 # hack around API to get raw bind values
79 256 ▶ no warnings 'redefine';
Subroutine BEGIN: called CC=1 SCAR=0.0
80 12 ▶ local *DBIO::Storage::DBI::_format_for_trace = sub { $_[1] };
Subroutine __ANON__: called CC=1 SCAR=0.0
81 12 ▶ Class::C3->reinitialize if old_mro;
Branch: 1 branch
BranchTrueFalseTotal
if &old_mro() 0 12 12
82  
83 12 local $self->storage->{debugcb};
84 12 local $self->storage->{debugobj} = my $tracer_obj = DBIO::Test::SQLTracerObj->new;
85 12 local $self->storage->{debug} = 2;
86  
87 12 local $Test::Builder::Level = $Test::Builder::Level + 2;
88 12 $cref->();
89  
90 12 ▶ return $tracer_obj->{sqlbinds} || [];
Condition100%2/2
$tracer_obj->{'sqlbinds'} || []
l!l
84
MC/DC100%1/1
$tracer_obj->{'sqlbinds'} || []
$tracer_obj->{'sqlbinds'}
Truth table100%2/2
A
A= $tracer_obj->{'sqlbinds'}
Aresult
11
00
91 }
92  
93  
94 10 ▶sub is_executed_querycount {
Subroutine is_executed_querycount: called CC=6 SCAR=18.3
Pod documented
95 10 my ($self, $cref, $exp_counts, $msg) = @_;
96  
97 10 local $Test::Builder::Level = $Test::Builder::Level + 1;
98  
99 10 ▶ $self->throw_exception("Expecting an hashref of counts or an integer representing total query count")
Branch: 1 branch
BranchTrueFalseTotal
unless ref $exp_counts eq "HASH" or defined $exp_counts and not ref $exp_counts 0 10 10
Condition50%3/6
ref $exp_counts eq "HASH" or defined $exp_counts and not ref $exp_counts
l!l&&r!l&&!r
280
defined $exp_counts and not ref $exp_counts
!ll&&!rl&&r
008
MC/DC0%0/3
ref $exp_counts eq "HASH" or defined $exp_counts and not ref $exp_counts
ref $exp_counts eq "HASH" defined $exp_counts not ref $exp_counts
Truth table50%2/4
A or B and not(C)
A= ref $exp_counts eq "HASH"B= defined $exp_countsC= not ref $exp_counts
ABCresult
1XX1
0111
00X0
0100
100 unless ref $exp_counts eq 'HASH' or (defined $exp_counts and ! ref $exp_counts);
101  
102 10 my @got = map { $_->[0] } @{ $self->capture_executed_sql_bind($cref) };
103  
104 10 ▶ return Test::More::is( scalar @got, $exp_counts, $msg )
Branch: 1 branch
BranchTrueFalseTotal
unless ref $exp_counts 8 2 10
105 unless ref $exp_counts;
106  
107 2 my $got_counts = { map { $_ => 0 } keys %$exp_counts };
108 2 $got_counts->{$_}++ for @got;
109  
110 2 return Test::More::is_deeply(
111 $got_counts,
112 $exp_counts,
113 $msg,
114 );
115 }
116  
117  
118 0 ▶sub is_executed_sql_bind {
Subroutine is_executed_sql_bind: not called CC=15 SCAR=54.8
Pod documented
119 0 my ($self, $cref, $sqlbinds, $msg) = @_;
120  
121 0 local $Test::Builder::Level = $Test::Builder::Level + 1;
122  
123 0 ▶ $self->throw_exception("Expecting an arrayref of SQL/Bind pairs") unless ref $sqlbinds eq 'ARRAY';
Branch: 1 branch
BranchTrueFalseTotal
unless ref $sqlbinds eq "ARRAY" 0 0 0
124  
125 0 my @expected = @$sqlbinds;
126  
127 0 my @got = map { $_->[1] } @{ $self->capture_executed_sql_bind($cref) };
128  
129 0 ▶ return Test::Builder->new->ok(1, $msg || "No queries executed while running $cref")
Branch: 1 branch
BranchTrueFalseTotal
unless @got or @expected 0 0 0
Condition0%0/5
@got or @expected
l!l&&r!l&&!r
000
$msg || "No queries executed while running $cref"
l!l
00
MC/DC0%0/2
@got or @expected
@got @expected
MC/DC0%0/1
$msg || "No queries executed while running $cref"
$msg
Truth table0%0/3
A or B
A= @gotB= @expected
ABresult
1X1
011
000
Truth table0%0/2
A
A= $msg
Aresult
11
00
130 if !@got and !@expected;
131  
132 0 require SQL::Abstract::Test;
133 0 my $ret = 1;
134 0 ▶ while (@expected or @got) {
Branch: 1 branch
BranchTrueFalseTotal
if (@expected or @got) 0 0 0
Condition0%0/3
@expected or @got
l!l&&r!l&&!r
000
MC/DC0%0/2
@expected or @got
@expected @got
Truth table0%0/3
A or B
A= @expectedB= @got
ABresult
1X1
011
000
135 0 my $left = shift @got;
136 0 my $right = shift @expected;
137  
138 0 ▶ if ($left and $right) {
Branch: 1 branch
BranchTrueFalseTotal
if ($left and $right) 0 0 0
Condition0%0/3
$left and $right
!ll&&!rl&&r
000
MC/DC0%0/2
$left and $right
$left $right
Truth table0%0/3
A and B
A= $leftB= $right
ABresult
0X0
100
111
139 0 $left = [ @$left ];
140 0 for my $i (1..$#$right) {
141 0 ▶ if (
Branch: 1 branch
BranchTrueFalseTotal
if (not ref $right->[$i] and ref $left->[$i] eq "ARRAY" and @{$left->[$i];} == 2) 0 0 0
Condition0%0/6
not ref $right->[$i] and ref $left->[$i] eq "ARRAY" and @{$left->[$i];} == 2
!ll&&!rl&&r
000
not ref $right->[$i] and ref $left->[$i] eq "ARRAY"
!ll&&!rl&&r
000
MC/DC0%0/3
not ref $right->[$i] and ref $left->[$i] eq "ARRAY" and @{$left->[$i];} == 2
not ref $right->[$i] ref $left->[$i] eq "ARRAY" @{$left->[$i];} == 2
Truth table0%0/4
not(A) and B and C
A= not ref $right->[$i]B= ref $left->[$i] eq "ARRAY"C= @{$left->[$i];} == 2
ABCresult
0XX0
10X0
1100
1111
142 ! ref $right->[$i]
143 and
144 ref $left->[$i] eq 'ARRAY'
145 and
146 0 @{$left->[$i]} == 2
147 ) {
148 0 $left->[$i] = $left->[$i][1]
149 }
150 }
151 }
152  
153 0 ▶ $ret &= SQL::Abstract::Test::is_same_sql_bind(
Condition0%0/4
$left || []
l!l
00
$right || []
l!l
00
MC/DC0%0/1
$left || []
$left
MC/DC0%0/1
$right || []
$right
Truth table0%0/2
A
A= $left
Aresult
11
00
Truth table0%0/2
A
A= $right
Aresult
11
00
154 \( $left || [] ),
155 \( $right || [] ),
156 $msg,
157 );
158 }
159  
160 0 return $ret;
161 }
162  
163 256 1;
164  
165 __END__
« blib/lib/DBIO/Test/Util/LeakTracer.pm ↑ Summary blib/lib/DBIO/SQL/Util.pm »