1Test::TinyMocker(3)   User Contributed Perl Documentation  Test::TinyMocker(3)
2
3
4

NAME

6       Test::TinyMocker
7

VERSION

9       version 0.05
10

SYNOPSIS

12           use Test::More;
13           use Test::TinyMocker;
14
15           mock 'Some::Module'
16               => method 'some_method'
17               => should {
18                   return $mocked_value;
19               };
20
21           # or
22
23           mock 'Some::Module'
24               => methods [ 'this_method', 'that_method' ]
25               => should {
26                   return $mocked_value;
27               };
28
29           # or
30
31           mock 'Some::Module::some_method'
32               => should {
33                   return $mocked_value;
34               };
35
36           # Some::Module::some_method() will now always return $mocked_value;
37
38               # To restore the original method
39
40               unmock 'Some::Module::some_method';
41
42           # or
43
44               unmock 'Some::Module' => method 'some_method';
45
46           # or
47
48           unmock 'Some::Module' => methods [ 'this_method', 'that_method' ];
49

NAME

51       Test::TinyMocker - a very simple tool to mock external modules
52

EXPORT

54   mock($module, $method_or_methods, $sub, $options)
55       This function allows you to overwrite the given method with an
56       arbitrary code block. This lets you simulate soem kind of behaviour for
57       your tests.
58
59       Alternatively, this method can be passed only two arguments, the first
60       one will be the full path of the method (pcakge name + method name) and
61       the second one the coderef.
62
63       An options HashRef can be passed as the last argument. Currently one
64       option is supported: "ignore_unknown" (default false) which when sets
65       to true allows to mock an unknown symbol.
66
67       Syntactic sugar is provided ("method", "methods" and "should") in order
68       to let you write sweet mock statements:
69
70           # This:
71           mock('Foo::Bar', 'a_method', sub { return 42;});
72
73           # is the same as:
74           mock 'Foo::Bar' => method 'a_method' => should { return 42 };
75
76           # or:
77           mock 'Foo::Bar::a_method' => should { return 42 };
78
79           # or also:
80           mock('Foo::Bar::a_method', sub { return 42;});
81
82       Using multiple methods at the same time can be done with arrayrefs:
83
84           # This:
85           mock('Foo::Bar', ['a_method', 'b_method'], sub { 42 } );
86
87           # is the same as:
88           mock 'Foo::Bar' => methods ['a_method', 'b_method'] => should { 42 };
89
90   unmock($module, $method_or_methods)
91       Syntactic sugar is provided ("method" and "methods") in order to let
92       you write sweet unmock statements:
93
94           # This:
95           unmock('Foo::Bar', 'a_method');
96
97           # is the same as:
98           unmock 'Foo::Bar' => method 'a_method';
99
100       And using multiple methods at the same time:
101
102           unmock 'Foo::Bar' => methods ['a_method', 'b_method'];
103
104   method
105       Syntactic sugar for mock()
106
107   methods
108       Syntactic sugar for mock()
109
110   should
111       Syntactic sugar for mock()
112

AUTHOR

114       Alexis Sukrieh, "<sukria at sukria.net>"
115

BUGS

117       Please report any bugs or feature requests to "bug-test-tinymocker at
118       rt.cpan.org", or through the web interface at
119       <http://rt.cpan.org/NoAuth/ReportBug.html?Queue=Test-TinyMocker>.  I
120       will be notified, and then you'll automatically be notified of progress
121       on your bug as I make changes.
122

SUPPORT

124       You can find documentation for this module with the perldoc command.
125
126           perldoc Test::TinyMocker
127
128       You can also look for information at:
129
130       •   RT: CPAN's request tracker
131
132           <http://rt.cpan.org/NoAuth/Bugs.html?Dist=Test-TinyMocker>
133
134       •   AnnoCPAN: Annotated CPAN documentation
135
136           <http://annocpan.org/dist/Test-TinyMocker>
137
138       •   CPAN Ratings
139
140           <http://cpanratings.perl.org/d/Test-TinyMocker>
141
142       •   Search CPAN
143
144           <http://search.cpan.org/dist/Test-TinyMocker/>
145

ACKNOWLEDGEMENTS

147       This module was inspired by Gugod's blog, after the article published
148       about mocking in Ruby and Perl: <http://gugod.org/2009/05/mocking.html>
149
150       This module was first part of the test tools provided by Dancer in its
151       own t directory (previously named "t::lib::EasyMocker"). A couple of
152       developers asked me if I could released this module as a real Test::
153       distribution on CPAN, so here it is.
154
156       Copyright 2010 Alexis Sukrieh.
157
158       This program is free software; you can redistribute it and/or modify it
159       under the terms of either: the GNU General Public License as published
160       by the Free Software Foundation; or the Artistic License.
161
162       See http://dev.perl.org/licenses/ for more information.
163

AUTHOR

165       Alexis Sukrieh <sukria@sukria.net>
166
168       This software is copyright (c) 2013 by Alexis Sukrieh.
169
170       This is free software; you can redistribute it and/or modify it under
171       the same terms as the Perl 5 programming language system itself.
172
173
174
175perl v5.36.0                      2023-01-20               Test::TinyMocker(3)
Impressum