Test/Role/MySQL.pm

filter: Statementstmt 48.6% 18 / 37 Branchbran 16.6% 2 / 12 Conditioncond n/a MC/DCmcdc n/a Subroutinesub 50.0% 5 / 10 Podpod 100% 2 / 2 totaltotal 44.2% 27 / 61 CC 7 SCAR 16.8
CC
7
Cov
41%
BUILD
11.6
__ANON__
6.0
_build_database
3.0
CRAP 5.4
« Schema/Result/Message.pm ↑ Summary Schema/Populate/StateLocale.pm »
1 package Interchange6::Test::Role::MySQL;
2  
3 =head1 NAME
4  
5 Interchange6::Test::Role::MySQL
6  
7 =cut
8  
9 1 ▶use Class::Load qw/try_load_class/;
Subroutine BEGIN: called CC=1 SCAR=0.0
10 1 ▶use File::Temp qw/tempdir/;
Subroutine BEGIN: called CC=1 SCAR=0.0
11 1 ▶use Test::Roo::Role;
Subroutine BEGIN: called CC=1 SCAR=0.0
12 1 with 'Interchange6::Test::Role::Database';
13  
14 =head1 METHODS
15  
16 See also L<Interchange6::Test::Role::Database> which is consumed by this role.
17  
18 =head2 BUILD
19  
20 Check that all required modules load or else plan skip_all
21  
22 =cut
23  
24 sub BUILD {
25 1 ▶ my $self = shift;
Subroutine BUILD: called CC=5 SCAR=24.5
Pod documented
26  
27 1 ▶ try_load_class('DateTime::Format::MySQL')
Branch: 1 branch
BranchTrueFalseTotal
try_load_class("DateTime::Format::MySQL") or plan("skip_all", "DateTime::Format::MySQL required to run these tests") 0 1 1
28 or plan skip_all => "DateTime::Format::MySQL required to run these tests";
29  
30 1 ▶ try_load_class('DBD::mysql')
Branch: 1 branch
BranchTrueFalseTotal
try_load_class("DBD::mysql") or plan("skip_all", "DBD::mysql required to run these tests") 1 0 1
31 or plan skip_all => "DBD::mysql required to run these tests";
32  
33 0 ▶ try_load_class('Test::mysqld')
Branch: 1 branch
BranchTrueFalseTotal
try_load_class("Test::mysqld") or plan("skip_all", "Test::mysqld required to run these tests") 0 0 0
34 or plan skip_all => "Test::mysqld required to run these tests";
35  
36 0 ▶ eval { $self->database }
Branch: 1 branch
BranchTrueFalseTotal
eval { do { $self->database } } or plan("skip_all", "Init database failed: $@") 0 0 0
37 or plan skip_all => "Init database failed: $@";
38 }
39  
40 1 my $tmpdir = tempdir(
41 CLEANUP => 1,
42 TEMPLATE => 'ic6s_test_XXXXX',
43 TMPDIR => 1,
44 );
45  
46 sub _build_database {
47 0 ▶ my $self = shift;
Subroutine _build_database: not called CC=2 SCAR=10.9
48 1 ▶ no warnings 'once'; # prevent: "Test::mysqld::errstr" used only once
Subroutine BEGIN: called CC=1 SCAR=0.0
49 0 ▶ my $mysqld = Test::mysqld->new(
Branch: 1 branch
BranchTrueFalseTotal
my $mysqld = "Test::mysqld"->new("base_dir", $tmpdir, "my_cnf", {"character-set-server", "utf8", "collation-server", "utf8_unicode_ci", "skip-networking", ""}) or die $Test::mysqld::errstr 0 0 0
50 base_dir => $tmpdir,
51 my_cnf => {
52 'character-set-server' => 'utf8',
53 'collation-server' => 'utf8_unicode_ci',
54 'skip-networking' => '',
55 }
56 ) or die $Test::mysqld::errstr;
57 0 return $mysqld;
58 }
59  
60 sub _build_dbd_version {
61 0 ▶ my $self = shift;
Subroutine _build_dbd_version: not called CC=1 SCAR=6.9
62 return
63 "DBD::mysql $DBD::mysql::VERSION Test::mysqld "
64 . "$Test::mysqld::VERSION mysql_clientversion "
65 0 . $self->ic6s_schema->storage->dbh->{mysql_clientversion};
66 }
67  
68 =head2 connect_info
69  
70 Returns appropriate DBI connect info for this role.
71  
72 =cut
73  
74 sub connect_info {
75 0 ▶ my $self = shift;
Subroutine connect_info: not called CC=1 SCAR=6.9
Pod documented
76 return (
77 0 $self->database->dsn( dbname => 'test' ),
78 undef, undef,
79 {
80 mysql_enable_utf8 => 1,
81 on_connect_do => [
82 q|SET SQL_MODE = CONCAT('ANSI,TRADITIONAL', @@sql_mode)|,
83 q|SET SQL_AUTO_IS_NULL = 0|,
84 ],
85 quote_names => 1,
86 }
87 );
88 }
89  
90 sub _build_database_info {
91 0 ▶ my $self = shift;
Subroutine _build_database_info: not called CC=1 SCAR=6.9
92 $self->ic6s_schema->storage->dbh_do(
93 sub {
94 0 ▶ my ( $storage, $dbh ) = @_;
Subroutine __ANON__: not called CC=2 SCAR=17.9
95 0 my $variables = $dbh->selectall_arrayref(q(SHOW VARIABLES));
96 0 my @info = map { $_->[0] =~ s/_server//; "$_->[0]=$_->[1]" } grep {
97 0 ▶ $_->[0] =~ /^(version|character_set_server|collation_server)/
Branch: 1 branch
BranchTrueFalseTotal
$_->[0] =~ /^(version|character_set_server|collation_server)/ and not $_->[0] =~ /compile/ 0 0 0
98 && $_->[0] !~ /compile/
99 } @$variables;
100 0 return join( " ", @info );
101 }
102 0 );
103 }
104  
105 1 1;
« Schema/Result/Message.pm ↑ Summary Schema/Populate/StateLocale.pm »