Class/Role/Object.pm

filter: Statementstmt 97.5% 40 / 41 Branchbran 50.0% 2 / 4 Conditioncond n/a MC/DCmcdc n/a Subroutinesub 100% 11 / 11 Podpod 100% 2 / 2 totaltotal 94.8% 55 / 58 CC 3 SCAR 4.0
CC
3
Cov
93%
mock_invoke
3.1
BEGIN
1.0
BEGIN
1.0
CRAP 1.5
↑ Summary Class.pm »
1 #!/usr/bin/perl -c
2  
3 package Test::Builder::Mock::Class::Role::Object;
4  
5 =head1 NAME
6  
7 Test::Builder::Mock::Class::Role::Object - Role for base object of mock class
8  
9 =head1 DESCRIPTION
10  
11 This role provides an API for changing behavior of mock class.
12  
13 =cut
14  
15 2 ▶use 5.006;
Subroutine BEGIN: called CC=1 SCAR=0.0
16  
17 2 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
18 2 ▶use warnings;
Subroutine BEGIN: called CC=1 SCAR=0.0
19  
20 2 our $VERSION = '0.0203';
21  
22 2 ▶use Moose::Role 0.89;
Subroutine BEGIN: called CC=1 SCAR=0.0
23  
24  
25 =head1 INHERITANCE
26  
27 =over 2
28  
29 =item *
30  
31 with L<Test::Mock::Class::Role::Object>
32  
33 =back
34  
35 =cut
36  
37 2 with 'Test::Mock::Class::Role::Object' => {
38 -alias => {
39 mock_invoke => '_mock_invoke_base',
40 mock_tally => '_mock_tally_base',
41 },
42 -excludes => [ 'mock_invoke', 'mock_tally' ],
43 };
44  
45  
46 2 ▶use English '-no_match_vars';
Subroutine BEGIN: called CC=1 SCAR=0.0
47  
48 2 ▶use Test::Builder;
Subroutine BEGIN: called CC=1 SCAR=0.0
49  
50  
51 2 ▶use Exception::Base (
Subroutine BEGIN: called CC=1 SCAR=0.0
52 2 '+ignore_package' => [__PACKAGE__],
53 2 );
54  
55  
56 =head1 ATTRIBUTES
57  
58 =over
59  
60 =item B<_mock_test_builder> : Test::Builder
61  
62 The L<Test::Builder> singleton object.
63  
64 =back
65  
66 =cut
67  
68 has '_mock_test_builder' => (
69 is => 'rw',
70 2 ▶ default => sub { Test::Builder->new },
Subroutine __ANON__: called CC=1 SCAR=0.0
71 2 );
72  
73  
74 2 ▶use namespace::clean -except => 'meta';
Subroutine BEGIN: called CC=1 SCAR=0.0
75  
76  
77 ## no critic qw(RequireCheckingReturnValueOfEval)
78  
79 =head1 METHODS
80  
81 =over
82  
83 =item B<mock_tally>(I<>) : Self
84  
85 Check the expectations at the end. See L<Test::Mock::Class::Role::Object> for
86 more description.
87  
88 The test passes if original C<mock_tally> method doesn't throw an exception.
89  
90 =cut
91  
92 2 ▶sub mock_tally {
Subroutine mock_tally: called CC=1 SCAR=0.0
Pod documented
93 2 my ($self) = @_;
94  
95 2 my $return = eval {
96 2 $self->_mock_tally_base;
97 };
98 2 $self->_mock_test_builder->is_eq($EVAL_ERROR, '', 'mock_tally()');
99  
100 2 return $return;
101 };
102  
103  
104 =item B<mock_invoke>( I<method> : Str, I<args> : Array ) : Any
105  
106 Returns the expected value for the method name and checks expectations. See
107 L<Test::Mock::Class::Role::Object> for more description.
108  
109 The test passes if original C<mock_tally> method doesn't throw an exception.
110  
111 =cut
112  
113 11 ▶sub mock_invoke {
Subroutine mock_invoke: called CC=3 SCAR=11.4
Pod documented
114 11 my ($self, $method, @args) = @_;
115  
116 11 my ($return, @return);
117 11 eval {
118 11 ▶ if (wantarray) {
Branch: 1 branch
BranchTrueFalseTotal
if (wantarray) { } 0 11 11
119 0 @return = $self->_mock_invoke_base($method, @args);
120 }
121 else {
122 11 $return = $self->_mock_invoke_base($method, @args);
123 };
124 };
125 11 $self->_mock_test_builder->is_eq($EVAL_ERROR, '', "mock_invoke($method)");
126  
127 11 ▶ return wantarray ? @return : $return;
Branch: 1 branch
BranchTrueFalseTotal
wantarray ? : 0 11 11
128 };
129  
130  
131 2 1;
132  
133  
134 =back
135  
136 =begin umlwiki
137  
138 = Class Diagram =
139  
140 [ <<role>>
141 Test::Builder::Mock::Class::Role::Object
142 -----------------------------------------------------------------------------
143 #_mock_test_builder : Test::Builder
144 -----------------------------------------------------------------------------
145 +mock_tally() : Self
146 +mock_invoke( method : Str, args : Array ) : Any
147 ]
148  
149 [Test::Builder::Mock::Class::Role::Object] ---|> [<<role>> Test::Mock::Class::Role::Object]
150  
151 =end umlwiki
152  
153 =head1 SEE ALSO
154  
155 L<Test::Mock::Class::Role::Object>, L<Test::Mock::Class>.
156  
157 =head1 BUGS
158  
159 The API is not stable yet and can be changed in future.
160  
161 =head1 AUTHOR
162  
163 Piotr Roszatycki <dexter@cpan.org>
164  
165 =head1 LICENSE
166  
167 Based on SimpleTest, an open source unit test framework for the PHP
168 programming language, created by Marcus Baker, Jason Sweat, Travis Swicegood,
169 Perrick Penet and Edward Z. Yang.
170  
171 Copyright (c) 2009, 2010 Piotr Roszatycki <dexter@cpan.org>.
172  
173 This program is free software; you can redistribute it and/or modify it
174 under GNU Lesser General Public License.
↑ Summary Class.pm »