Test::TinyMocker(3)
β¨ NAME β¨
okay so Test::TinyMocker π β it's a very simple tool to mock external modules. that's the whole vibe bestie, no cap.
πΈ VERSION πΈ
version 0.05 β tiny but mighty, periodt. π
π¦ SYNOPSIS π¦
here's the tea, literally exactly how you'd write it:
use Test::More;
use Test::TinyMocker;
mock 'Some::Module'
=> method 'some_method'
=> should {
return $mocked_value;
};
# or
mock 'Some::Module'
=> methods [ 'this_method', 'that_method' ]
=> should {
return $mocked_value;
};
# or
mock 'Some::Module::some_method'
=> should {
return $mocked_value;
};
# Some::Module::some_method() will now always return $mocked_value;
# To restore the original method
unmock 'Some::Module::some_method';
# or
unmock 'Some::Module' => method 'some_method';
# or
unmock 'Some::Module' => methods [ 'this_method', 'that_method' ];
π NAME (again, yes really) π
Test::TinyMocker β a very simple tool to mock external modules π«Ά
π EXPORT π
mock($module, $method_or_methods, $sub, $options)
this one lets you overwrite the given method with an arbitrary code block. so you can simulate some kind of behaviour for your tests. iconic, honestly. β¨
alternatively, this method can be passed only two arguments β the first one is the full path of the method (package name + method name, iykyk) and the second one is the coderef.
an options HashRef can be passed as the last argument. currently one option is supported:
ignore_unknownβ defaultfalse; when it's set totrue, it allows you to mock an unknown symbol. π
syntactic sugar is provided (method, methods and should) so you can write sweet mock statements, and honestly? obsessed:
# This:
mock('Foo::Bar', 'a_method', sub { return 42;});
# is the same as:
mock 'Foo::Bar' => method 'a_method' => should { return 42 };
# or:
mock 'Foo::Bar::a_method' => should { return 42 };
# or also:
mock('Foo::Bar::a_method', sub { return 42;});
using multiple methods at the same time can be done with arrayrefs β the way that works is just β¨chef's kissβ¨:
# This:
mock('Foo::Bar', ['a_method', 'b_method'], sub { 42 } );
# is the same as:
mock 'Foo::Bar' => methods ['a_method', 'b_method'] => should { 42 };
unmock($module, $method_or_methods)
syntactic sugar is provided (method and methods) so you can write sweet unmock statements π:
# This:
unmock('Foo::Bar', 'a_method');
# is the same as:
unmock 'Foo::Bar' => method 'a_method';
and using multiple methods at the same time:
unmock 'Foo::Bar' => methods ['a_method', 'b_method'];
method
syntactic sugar for mock() π
methods
syntactic sugar for mock() π
should
syntactic sugar for mock() π
π AUTHOR π
Alexis Sukrieh, <sukria at sukria.net> β thank you king πββοΈ
π BUGS π
please report any bugs or feature requests to bug-test-tinymocker at rt.cpan.org, or through the web interface at http://rt.cpan.org/NoAuth/ReportBug.html?Queue=Test-TinyMocker. he will be notified, and then you'll automatically be notified of progress on your bug as changes get made. teamwork fr fr π«Ά
π SUPPORT π
you can find documentation for this module with the perldoc command:
perldoc Test::TinyMocker
you can also look for information at:
- RT: CPAN's request tracker
http://rt.cpan.org/NoAuth/Bugs.html?Dist=Test-TinyMocker
- AnnoCPAN: Annotated CPAN documentation
http://annocpan.org/dist/Test-TinyMocker
- CPAN Ratings
http://cpanratings.perl.org/d/Test-TinyMocker
- Search CPAN
http://search.cpan.org/dist/Test-TinyMocker/
π§ ACKNOWLEDGEMENTS π§
this module was inspired by Gugod's blog, after the article published about mocking in Ruby and Perl: http://gugod.org/2009/05/mocking.html π
this module was first part of the test tools provided by Dancer in its own t directory (previously named t::lib::EasyMocker). a couple of developers asked if it could be released as a real Test:: distribution on CPAN, so here it is. main character origin story, honestly. π
π LICENSE AND COPYRIGHT π
Copyright 2010 Alexis Sukrieh.
this program is free software; you can redistribute it and/or modify it under the terms of either: the GNU General Public License as published by the Free Software Foundation; or the Artistic License.
see http://dev.perl.org/licenses/ for more information.
π AUTHOR (yes, again) π
Alexis Sukrieh <sukria@sukria.net>
β COPYRIGHT AND LICENSE β
this software is copyright (c) 2013 by Alexis Sukrieh.
this is free software; you can redistribute it and/or modify it under the same terms as the Perl 5 programming language system itself.
and that's the whole page bestie!! π this was rendered by perl v5.42.0 on 2025-07-25 β so like, remember who brought you here when you're out there mocking everything in sight. slay, hydrate, and unmock your methods when you're done. π
β¨π¦
π¦ where this page comes from
- fedora 43: perl-Test-TinyMocker 0.05-34.fc43 Β· GPL-1.0-or-later OR Artistic-1.0-Perl
- π girlified by deepseek-ai/DeepSeek-V4.1-Flash on : a language model's rewrite of the original, under its terms