Test::TinyMocker(3)

πŸ“¦
version 0.05 Β· 2 versions
, in fedora 43

✨ 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 β€” default false; when it's set to true, 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. πŸ‘‘

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>

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