Test/Role/SQLite.pm

filter: Statementstmt 95.8% 23 / 24 Branchbran 50.0% 2 / 4 Conditioncond n/a MC/DCmcdc n/a Subroutinesub 90.0% 9 / 10 Podpod 100% 3 / 3 totaltotal 90.2% 37 / 41 CC 3 SCAR 3.6
CC
3
Cov
89%
clear_database
2.1
BUILD
2.0
_build_database
2.0
CRAP 1.4
« Schema/Component/Validation.pm ↑ Summary Schema/Result/OrderlinesShipping.pm »
1 package Interchange6::Test::Role::SQLite;
2  
3 =head1 NAME
4  
5 Interchange6::Test::Role::SQLite
6  
7 =cut
8  
9 2 ▶use File::Temp;
Subroutine BEGIN: called CC=1 SCAR=0.0
10 2 ▶use Test::Roo::Role;
Subroutine BEGIN: called CC=1 SCAR=0.0
11 2 with 'Interchange6::Test::Role::Database';
12  
13 =head1 METHODS
14  
15 See also L<Interchange6::Test::Role::Database> which is consumed by this role.
16  
17 =head2 BUILD
18  
19 Check that all required modules load or else plan skip_all
20  
21 =cut
22  
23 sub BUILD {
24 1 ▶ eval('use DBD::SQLite; 1')
Subroutine BUILD: called CC=2 SCAR=7.0
Subroutine BEGIN: called CC=1 SCAR=0.0
Pod documented
Branch: 1 branch
BranchTrueFalseTotal
eval "use DBD::SQLite; 1" or plan("skip_all", "DBD::SQLite required to run these tests") 0 1 1
25 or plan skip_all => "DBD::SQLite required to run these tests";
26 }
27  
28 2 my $fh = File::Temp->new(
29 TEMPLATE => 'ic6s_test_XXXXX',
30 EXLOCK => 0,
31 TMPDIR => 1,
32 );
33 2 my $dbfile = $fh->filename;
34  
35 after teardown => sub {
36 1 ▶ shift->clear_database;
Subroutine __ANON__: called CC=1 SCAR=0.0
37 2 };
38  
39 =head2 clear_database
40  
41 Attempt to unlink temporary database file
42  
43 =cut
44  
45 sub clear_database {
46 1 ▶ close($fh);
Subroutine clear_database: called CC=2 SCAR=7.2
Pod documented
47 1 ▶ unlink($dbfile) or diag "Could not unlink $dbfile: $!";
Branch: 1 branch
BranchTrueFalseTotal
unlink $dbfile or diag("Could not unlink ${dbfile}: $!") 0 1 1
48 }
49  
50 sub _build_database {
51  
52 # does nothing atm for SQLite
53 0 ▶ return;
Subroutine _build_database: not called CC=1 SCAR=6.9
54 }
55  
56 sub _build_dbd_version {
57 1 ▶ return "DBD::SQLite $DBD::SQLite::VERSION";
Subroutine _build_dbd_version: called CC=1 SCAR=0.0
58 }
59  
60 =head2 connect_info
61  
62 Returns appropriate DBI connect info for this role.
63  
64 =cut
65  
66 sub connect_info {
67 1 ▶ my $self = shift;
Subroutine connect_info: called CC=1 SCAR=0.0
Pod documented
68  
69 1 return ( "dbi:SQLite:dbname=$dbfile", undef, undef,
70 {
71 sqlite_unicode => 1,
72 on_connect_call => 'use_foreign_keys',
73 on_connect_do => 'PRAGMA synchronous = OFF',
74 quote_names => 1,
75 }
76 );
77 }
78  
79 sub _build_database_info {
80 1 ▶ my $self = shift;
Subroutine _build_database_info: called CC=1 SCAR=0.0
81 return "SQLite library version: "
82 1 . $self->ic6s_schema->storage->dbh->{sqlite_version};
83 }
84  
85 2 1;
« Schema/Component/Validation.pm ↑ Summary Schema/Result/OrderlinesShipping.pm »