Test/Role/MySQL.pm

filter: Statementstmt 50.0% 22 / 44 Branchbran 16.6% 2 / 12 Conditioncond n/a MC/DCmcdc n/a Subroutinesub 58.3% 7 / 12 Podpod 100% 2 / 2 totaltotal 47.1% 33 / 70 CC 7 SCAR 13.7
CC
7
Cov
43%
BUILD
9.2
__ANON__
3.8
_build_database
3.0
CRAP 3.9
« Schema/Base/Attribute.pm ↑ Summary Schema/Result/User.pm »
1 package Interchange6::Test::Role::MySQL;
2  
3 =head1 NAME
4  
5 Interchange6::Test::Role::MySQL
6  
7 =cut
8  
9 1 ▶use File::Temp qw/tempdir/;
Subroutine BEGIN: called CC=1 SCAR=0.0
10 1 ▶use Test::Roo::Role;
Subroutine BEGIN: called CC=1 SCAR=0.0
11 1 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 ▶ my $self = shift;
Subroutine BUILD: called CC=5 SCAR=22.1
Pod documented
25  
26 1 ▶ eval 'use DateTime::Format::MySQL; 1'
Subroutine BEGIN: called CC=1 SCAR=0.0
Branch: 1 branch
BranchTrueFalseTotal
eval "use DateTime::Format::MySQL; 1" or plan("skip_all", "DateTime::Format::MySQL required to run these tests") 0 1 1
27 or plan skip_all => "DateTime::Format::MySQL required to run these tests";
28  
29 1 ▶ eval 'use DBD::mysql; 1'
Subroutine BEGIN: called CC=1 SCAR=1.2
Branch: 1 branch
BranchTrueFalseTotal
eval "use DBD::mysql; 1" or plan("skip_all", "DBD::mysql required to run these tests") 1 0 1
30 or plan skip_all => "DBD::mysql required to run these tests";
31  
32 0 ▶ eval 'use Test::mysqld; 1'
Branch: 1 branch
BranchTrueFalseTotal
eval "use Test::mysqld; 1" or plan("skip_all", "Test::mysqld required to run these tests") 0 0 0
33 or plan skip_all => "Test::mysqld required to run these tests";
34  
35 0 ▶ eval { $self->database }
Branch: 1 branch
BranchTrueFalseTotal
eval { do { $self->database } } or plan("skip_all", "Init database failed: $@") 0 0 0
36 or plan skip_all => "Init database failed: $@";
37 }
38  
39 1 my $tmpdir = tempdir(
40 CLEANUP => 1,
41 TEMPLATE => 'ic6s_test_XXXXX',
42 TMPDIR => 1,
43 );
44  
45 sub _build_database {
46 0 ▶ my $self = shift;
Subroutine _build_database: not called CC=2 SCAR=10.9
47 1 ▶ no warnings 'once'; # prevent: "Test::mysqld::errstr" used only once
Subroutine BEGIN: called CC=1 SCAR=0.0
48 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
49 base_dir => $tmpdir,
50 my_cnf => {
51 'character-set-server' => 'utf8',
52 'collation-server' => 'utf8_unicode_ci',
53 'skip-networking' => '',
54 }
55 ) or die $Test::mysqld::errstr;
56 0 return $mysqld;
57 }
58  
59 sub _build_dbd_version {
60 0 ▶ my $self = shift;
Subroutine _build_dbd_version: not called CC=1 SCAR=6.9
61 return
62 "DBD::mysql $DBD::mysql::VERSION Test::mysqld "
63 . "$Test::mysqld::VERSION mysql_clientversion "
64 0 . $self->ic6s_schema->storage->dbh->{mysql_clientversion};
65 }
66  
67 =head2 connect_info
68  
69 Returns appropriate DBI connect info for this role.
70  
71 =cut
72  
73 sub connect_info {
74 0 ▶ my $self = shift;
Subroutine connect_info: not called CC=1 SCAR=6.9
Pod documented
75 return (
76 0 $self->database->dsn( dbname => 'test' ),
77 undef, undef,
78 {
79 mysql_enable_utf8 => 1,
80 on_connect_call => 'set_strict_mode',
81 quote_names => 1,
82 }
83 );
84 }
85  
86 sub _build_database_info {
87 0 ▶ my $self = shift;
Subroutine _build_database_info: not called CC=1 SCAR=4.1
88 $self->ic6s_schema->storage->dbh_do(
89 sub {
90 0 ▶ my ( $storage, $dbh ) = @_;
Subroutine __ANON__: not called CC=2 SCAR=13.4
91 0 my $variables = $dbh->selectall_arrayref(q(SHOW VARIABLES));
92 0 my @info = map { $_->[0] =~ s/_server//; "$_->[0]=$_->[1]" } grep {
93 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
94 && $_->[0] !~ /compile/
95 } @$variables;
96 1 ▶ use DBI::Const::GetInfoType;
Subroutine BEGIN: called CC=1 SCAR=0.0
97 0 push @info, $dbh->get_info( $GetInfoType{SQL_DBMS_VER} );
98 0 return join( " ", @info );
99 }
100 0 );
101 }
102  
103 1 1;
« Schema/Base/Attribute.pm ↑ Summary Schema/Result/User.pm »