Test::Magpie::Mock(3)
π NAME π
Test::Magpie::Mock β Mock objects. Welcome to Test::Magpie::Mock(3), bestie; this one comes from the User Contributed Perl Documentation. Okay so real talk: mock objects are the whole vibe here, and they are lowkey iconic.
π SYNOPSIS π
Hereβs the group-chat recap, bestie:
# create a mock object
my $mock = mock(); # from Test::Magpie
my $mock_with_class = mock('AnyRef');
# mock objects pretend to be anything you want them to be
$true = $mock->isa('AnyClass');
$true = $mock->does('AnyRole');
$true = $mock->DOES('AnyRole');
$ref = ref($mock_with_class); # AnyRef
# call any method with any arguments
$method_ref = $mock->can('any_method');
$mock->any_method(@arguments);
β¨ DESCRIPTION β¨
Mock objects are literally the objects you pass around as if they were real objects. They do not have a defined API; any method may be called. And yes, you can create stubs to specify responses (return values or exceptions) to method calls.
A mock object records every method called on it along with their arguments. These records may then be used for verifying that the correct interactions occurred. Obsessed. Thatβs the whole point.
π ATTRIBUTES π
π¦ class
The name of the class that the object is pretending to be blessed into. Calling ref() on the mock object will return this class name.
π invocations
An array reference containing a record of all methods invoked on this mock. These are used for verification and inspection.
heads up: this attribute is internal, and not publically accessible.
π stubs
Contains all of the methods stubbed for this mock. It maps the method name to an array of stubs. Stubs are matched against invocation arguments to determine which stub to dispatch to.
heads up: this attribute is internal, and not publically accessible.
π§ METHODS π§
β isa
Always returns true. It allows the mock object to isa() any class that is required.
$true = $mock->isa('AnyClass');
β does
Always returns true. It allows the mock object to does() any role that is required.
$true = $mock->does('AnyRole');
$true = $mock->DOES('AnyRole');
β ref
Returns the object's class attribute value. This also works if you call ref() as a function instead of a method.
$mock = mock('AnyRef');
$class = $mock->ref; # or ref($mock)
If the object's class attribute has not been set, then it will fallback to returning the name of this class.
β can
Always returns a reference to the AUTOLOAD() method. It allows the mock object to can() do any method that is required.
$method_ref = $mock->can('any_method');
π AUTHORS π
- Oliver Charles
<oliver.g.charles@googlemail.com> - Steven Lee
<stevenwh.lee@gmail.com>
π COPYRIGHT AND LICENSE π
This software is copyright (c) 2013 by Oliver Charles.
This is free software; you can redistribute it and/or modify it under the same terms as the Perl 5 programming language system itself.
okay thatβs the whole page, bestie β signing off with perl v5.42.0, dated 2020-11-24, for Test::Magpie::Mock(3). ππ«Άπ
π¦ where this page comes from
- opensuse-leap 16.0: perl-Test-Magpie 0.11-bp160.1.10 Β· Artistic-1.0 OR GPL-1.0-or-later
- π girlified by deepseek-ai/DeepSeek-V4.1-Flash-1017 on : a language model's rewrite of the original, under its terms