lib/Class/DBI/Lite/Fixture.pm

filter: Statementstmt 80.0% 16 / 20 Branchbran n/a Conditioncond 50.0% 1 / 2 MC/DCmcdc 0.0% 0 / 1 Subroutinesub 60.0% 3 / 5 Podpod n/a totaltotal 71.4% 20 / 28 CC 2 SCAR 4.3
CC
2
Cov
77%
import
2.0
DESTROY
2.0
__ANON__
1.1
CRAP 1.5
« lib/Class/DBI/Lite/ColumnInfo.pm ↑ Summary lib/Class/DBI/Lite/Iterator.pm »
1  
2 package Class::DBI::Lite::Fixture;
3  
4 1 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
5 1 ▶use warnings 'all';
Subroutine BEGIN: called CC=1 SCAR=0.0
6  
7 1 my @destroys = ( );
8  
9 1 my $_instance;
10  
11  
12 sub import
13 1 ▶{
Subroutine import: called CC=2 SCAR=7.1
14 1 my ($class, @fixtures) = @_;
15
16 1 ▶ $_instance ||= bless { }, $class;
Condition50%1/2
$_instance ||= bless({}, $class)
l!l
01
MC/DC0%0/1
$_instance ||= bless({}, $class)
$_instance
Truth table50%1/2
A
A= $_instance
Aresult
11
00
17
18 map {
19 1 my $setup = "setup_$_";
20 1 my $destroy = "destroy_$_";
21 0 ▶ push @destroys, sub { $class->$destroy };
Subroutine __ANON__: not called CC=1 SCAR=1.2
22 1 $class->$setup
23 } @fixtures;
24 }# end import()
25  
26  
27 DESTROY
28 0 ▶{
Subroutine DESTROY: not called CC=1 SCAR=6.9
29 0 map { eval { $_->() } } @destroys;
30 }# end DESTROY()
31  
32 1 1;# return true:
33  
34 =pod
35  
36 =head1 NAME
37  
38 Class::DBI::Lite::Fixture - Test fixtures for easy testing.
39  
40 =head1 SYNOPSIS
41  
42 =head2 In Your Test Fixture
43  
44 package app::fixtures;
45  
46 use strict;
47 use warnings 'all';
48 use base 'Class::DBI::Lite::Fixture';
49 use app::state;
50  
51 my @state_info = qw( AL:Alabama AK:Alaska AR:Arkansas );
52 my @states = ( );
53  
54 sub setup_states {
55 push @states, map {
56 my ($abbr, $name) = split /\:/, $_;
57 app::state->find_or_create(
58 name => $name,
59 abbr => $abbr,
60 )
61 } @state_info;
62 }# end setup_states()
63  
64 sub destroy_states {
65 map { eval{$_->delete} } @states;
66 }# end destroy_states()
67  
68 1;# return true:
69  
70 =head2 In Your Test File
71  
72 use strict;
73 use warnings 'all';
74 use Test::More 'no_plan';
75 use lib qw( lib t/lib );
76
77 # Setup your test fixtures:
78 use app::fixtures 'states';
79
80 use_ok('app::state');
81 is(
82 app::state->count_search(abbr => 'AL') => 1
83 );
84
85 # The 'app::state' records are automatically deleted in 'destroy_states'!
86  
87 =head1 DESCRIPTION
88  
89 This module provides stubs for the use of "test fixtures" to test your code.
90  
91 =head1 AUTHOR
92  
93 Copyright John Drago <jdrago_999@yahoo.com>. All rights reserved.
94  
95 =head1 LICENSE
96  
97 This software is Free software and may be used and redistributed under the
98 same terms as perl itself.
99  
100 =cut
101  
« lib/Class/DBI/Lite/ColumnInfo.pm ↑ Summary lib/Class/DBI/Lite/Iterator.pm »