-
-
16 Aug 2013 08:36:22 UTC
- Distribution: Test-Magpie
- Module version: 0.11
- Source (raw)
- Browse (raw)
- Changes
- How to Contribute
- Repository
- Issues
- Testers (972 / 1 / 116)
- Kwalitee
Bus factor: 0- 88.24% Coverage
- License: perl_5
- Perl: v5.10.1
- Activity
24 month- Tools
- Download (24.87KB)
- MetaCPAN Explorer
- Permissions
- Subscribe to distribution
- Permalinks
- This version
- Latest version
and 1 contributors-
Oliver Charles
- Dependencies
- Carp
- Devel::PartialDump
- Exporter
- List::Util
- Moose
- Moose::Meta::Class
- Moose::Role
- Moose::Util
- MooseX::Types
- MooseX::Types::Moose
- MooseX::Types::Structured
- Scalar::Util
- Set::Object
- Test::Builder
- UNIVERSAL::ref
- aliased
- experimental
- namespace::autoclean
- overload
- strict
- warnings
- Reverse dependencies
- CPAN Testers List
- Dependency graph
NAME
Test::Magpie::Mock - Mock objects
SYNOPSIS
# 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 the objects you pass around as if they were real objects. They do not have a defined API; any method may be called. Additionally, you can create stubs to specify responses (return values or exceptions) to method calls.
A mock objects records every method called on it along with their arguments. These records may then be used for verifying that the correct interactions occured.
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.
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.
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 callref()
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 tocan()
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.
Module Install Instructions
To install Test::Magpie, copy and paste the appropriate command in to your terminal.
cpanm Test::Magpie
perl -MCPAN -e shell install Test::Magpie
For more information on module installation, please visit the detailed CPAN module installation guide.