Eve/Test.pm

filter: Statementstmt 58.3% 14 / 24 Branchbran n/a Conditioncond n/a MC/DCmcdc n/a Subroutinesub 71.4% 5 / 7 Podpod 100% 2 / 2 totaltotal 63.6% 21 / 33 CC 1 SCAR 2.5
CC
1
Cov
58%
is_lazy
2.0
is_prototype
2.0
BEGIN
1.0
CRAP 1.3
« Eve/Template.pm ↑ Summary Eve/Event/ExternalSignup.pm »
1 package Eve::Test;
2  
3 44 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
4 44 ▶use warnings;
Subroutine BEGIN: called CC=1 SCAR=0.0
5  
6 44 ▶use parent qw(Test::Class);
Subroutine BEGIN: called CC=1 SCAR=0.0
7  
8 44 ▶use Test::More;
Subroutine BEGIN: called CC=1 SCAR=0.0
9  
10 =head1 NAME
11  
12 B<Eve::Test> - a base class for all test cases.
13  
14 =head1 SYNOPSIS
15  
16 use parent qw(Eve::Test);
17  
18 sub startup : Test(startup) {
19 my $self = shift;
20  
21 $self->{'testcase_property'} = 'Testcase';
22 }
23  
24 sub setup : Test(setup) {
25 my $self = shift;
26  
27 $self->{'test_property'} = 'Test';
28 }
29  
30 sub test_match : Test(2) {
31 my $self = shift;
32  
33 is($something, $self->{'testcase_property'},
34 'Does something equal a testcase property?');
35 is($something, $self->{'test_property'},
36 'Does something equal a test property?');
37  
38 Eve::Test::is_lazy(
39 code => sub {
40 return $self->{'some_registry'}->get_some_lazy_service();
41 },
42 class_name => 'Some::Lazy::Service',
43 description =>
44 'Does the subroutine return the same instance of '
45 . 'Some::Lazy::Service?');
46  
47 Eve::Test::is_prototype(
48 code => sub {
49 return $self->{'some_registry'}->get_some_prototype_service();
50 },
51 class_name => 'Some::Prototype::Service',
52 description =>
53 'Does the subroutine return a different instance of '
54 . 'Some::Prototype::Service?');
55 }
56  
57 sub setup : Test(teardown) {
58 my $self = shift;
59  
60 undef $self->{'test_property'};
61 }
62  
63 sub shutdown : Test(shutdown) {
64 my $self = shift;
65  
66 undef $self->{'testcase_property'};
67 }
68  
69 =head1 DESCRIPTION
70  
71 B<Eve::Test> class uses the L<Test::Class> module as a base. Each
72 test case that wants to use its functionality should inherit from it.
73 After this it is easy to define setup/teardown, startup/shutdown and
74 test methods.
75  
76 =head2 Test methods
77  
78 A test method is specified as such by using special method attributes
79 like so:
80  
81 sub test_something : Test {
82 # Your test here
83 }
84  
85 If there is more than one test in the method, their count should be
86 specified:
87  
88 sub test_something : Test(4) {
89 # Your four tests here
90 }
91  
92 If there is no way to tell how many tests are going to be run in the
93 method, the 'no_plan' parameter can be used:
94  
95 sub test_something : Test(no_plan) {
96 # Your test here
97 }
98  
99 =head2 Abstract test classes
100  
101 To avoid running tests on abstract test classes call the SKIP_CLASS
102 method in the package.
103  
104 Eve::SomeAbstractClassTest->SKIP_CLASS(1);
105  
106 =cut
107  
108 17 ▶INIT { Test::Class->runtests() }
Subroutine INIT: called CC=1 SCAR=0.0
109  
110 =head1 METHODS
111  
112 =head2 B<is_lazy()>
113  
114 Asserts that a code block returns the same object on two sequential
115 calls and that this object is an instance of a certain class. When
116 using this assertion method add two tests to the plan for each call.
117  
118 use Eve::Test;
119  
120 sub test_lazy_service : Test(2) {
121 Eve::Test::is_lazy(
122 code => sub {
123 return $some_registry->some_lazy_service();
124 },
125 class_name => 'Some::Class::Name',
126 description => 'I need this service to be lazy!');
127 }
128  
129 =head3 Arguments
130  
131 =over 4
132  
133 =item C<code>
134  
135 =item C<class_name>
136  
137 =item C<description>
138  
139 (optional) defaults to undef.
140  
141 =back
142  
143 =cut
144  
145 0 ▶sub is_lazy {
Subroutine is_lazy: not called CC=1 SCAR=6.9
Pod documented
146 0 my (%arg_hash) = @_;
147 0 Eve::Support::arguments(\%arg_hash,
148 my ($code, $class_name), my $description = \undef);
149  
150 0 isa_ok($code->(), $class_name, $description);
151 0 is($code->(), $code->(), $description);
152  
153 0 return;
154 }
155  
156 =head2 B<is_prototype()>
157  
158 Asserts that a code block returns a different object on two sequential
159 calls and that this object is an instance of a certain class. When
160 using this assertion method add two tests to the plan for each call.
161  
162 use Eve::Test;
163  
164 sub test_prototype_service : Test(2) {
165 Eve::Test::is_prototype(
166 code => sub {
167 return $some_registry->some_prototype_service();
168 },
169 class_name => 'Some::Class::Name',
170 description => 'I need this service to be a prototype!');
171 }
172  
173 =head3 Arguments
174  
175 =over 4
176  
177 =item C<code>
178  
179 =item C<class_name>
180  
181 =item C<description>
182  
183 (optional) defaults to undef.
184  
185 =back
186  
187 =cut
188  
189 0 ▶sub is_prototype {
Subroutine is_prototype: not called CC=1 SCAR=6.9
Pod documented
190 0 my (%arg_hash) = @_;
191 0 Eve::Support::arguments(\%arg_hash,
192 my ($code, $class_name), my $description = \undef);
193  
194 0 isa_ok($code->(), $class_name, $description);
195 0 isnt($code->(), $code->(), $description);
196  
197 0 return;
198 }
199  
200 =head1 SEE ALSO
201  
202 =over 4
203  
204 =item L<Test::Class>
205  
206 =item L<Test::Simple>
207  
208 =item L<Test::More>
209  
210 =item L<Test::Exception>
211  
212 =item L<Test::MockObject>
213  
214 =back
215  
216 =head1 LICENSE AND COPYRIGHT
217  
218 Copyright 2012 Igor Zinovyev.
219  
220 This program is free software; you can redistribute it and/or modify it
221 under the terms of either: the GNU General Public License as published
222 by the Free Software Foundation; or the Artistic License.
223  
224 See http://dev.perl.org/licenses/ for more information.
225  
226  
227 =head1 AUTHORS
228  
229 =over 4
230  
231 =item L<Sergey Konoplev|mailto:gray.ru@gmail.com>
232  
233 =item L<Igor Zinovyev|mailto:zinigor@gmail.com>
234  
235 =cut
236  
237 44 1;
« Eve/Template.pm ↑ Summary Eve/Event/ExternalSignup.pm »