| 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
| |||||||||||||||||||||||||||||||||||||||||||
| 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
| |||||||||||||||||||||||||||||||||||||||||||
| 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'} || []
MC/DC100%1/1
$tracer_obj->{'sqlbinds'} || []
$tracer_obj->{'sqlbinds'}
Truth table100%2/2
A
A= $tracer_obj->{'sqlbinds'}
| |||||||||||||||||||||||||||||||||||||||||||
| 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
Condition50%3/6
ref $exp_counts eq "HASH" or defined $exp_counts and not ref $exp_counts
defined $exp_counts and not ref $exp_counts
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
| |||||||||||||||||||||||||||||||||||||||||||
| 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
| |||||||||||||||||||||||||||||||||||||||||||
| 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
| |||||||||||||||||||||||||||||||||||||||||||
| 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
Condition0%0/5
@got or @expected
$msg || "No queries executed while running $cref"
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
Truth table0%0/2
A
A= $msg
| |||||||||||||||||||||||||||||||||||||||||||
| 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
Condition0%0/3
@expected or @got
MC/DC0%0/2
@expected or @got
@expected
@got
Truth table0%0/3
A or B
A= @expectedB= @got
| |||||||||||||||||||||||||||||||||||||||||||
| 135 | 0 | my $left = shift @got; | |||||||||||||||||||||||||||||||||||||||||
| 136 | 0 | my $right = shift @expected; | |||||||||||||||||||||||||||||||||||||||||
| 137 | |||||||||||||||||||||||||||||||||||||||||||
| 138 | 0 | ▶ | if ($left and $right) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition0%0/3
$left and $right
MC/DC0%0/2
$left and $right
$left
$right
Truth table0%0/3
A and B
A= $leftB= $right
| |||||||||||||||||||||||||||||||||||||||||||
| 139 | 0 | $left = [ @$left ]; | |||||||||||||||||||||||||||||||||||||||||
| 140 | 0 | for my $i (1..$#$right) { | |||||||||||||||||||||||||||||||||||||||||
| 141 | 0 | ▶ | if ( | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition0%0/6
not ref $right->[$i] and ref $left->[$i] eq "ARRAY" and @{$left->[$i];} == 2
not ref $right->[$i] and ref $left->[$i] eq "ARRAY"
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
| |||||||||||||||||||||||||||||||||||||||||||
| 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 || []
$right || []
MC/DC0%0/1
$left || []
$left
MC/DC0%0/1
$right || []
$right
Truth table0%0/2
A
A= $left
Truth table0%0/2
A
A= $right
| |||||||||||||||||||||||||||||||||||||||||||
| 154 | \( $left || [] ), | ||||||||||||||||||||||||||||||||||||||||||
| 155 | \( $right || [] ), | ||||||||||||||||||||||||||||||||||||||||||
| 156 | $msg, | ||||||||||||||||||||||||||||||||||||||||||
| 157 | ); | ||||||||||||||||||||||||||||||||||||||||||
| 158 | } | ||||||||||||||||||||||||||||||||||||||||||
| 159 | |||||||||||||||||||||||||||||||||||||||||||
| 160 | 0 | return $ret; | |||||||||||||||||||||||||||||||||||||||||
| 161 | } | ||||||||||||||||||||||||||||||||||||||||||
| 162 | |||||||||||||||||||||||||||||||||||||||||||
| 163 | 256 | 1; | |||||||||||||||||||||||||||||||||||||||||
| 164 | |||||||||||||||||||||||||||||||||||||||||||
| 165 | __END__ | ||||||||||||||||||||||||||||||||||||||||||