|new( $object | $class )||
new() takes one optional argument, the object or class to mock. If youre
mocking a method for an object that holds internal state, create an appropriate
object, then pass it to this constructor. <B>NOTE:B> this will modify the object
If youre mocking an object that does not need state, as in the cases where theres no internal data or youll only be calling class methods, or where youll be mocking all of the access to internal data, you can pass in the name of the class to mock partially.
If youve not yet loaded the class, this method will try to load it for you. This may fail, so beware.
If you pass no arguments, it will assume you really meant to create a normal Test::MockObject object and will oblige you.
Note that if you pass a class, the object returned will appear to be an instance of that class; this does not mock the class itself.
|mock( $methodname, $sub_ref )||See the documentation for Test::MockObject for all of the ways to mock methods and to retrieve method logging information. These methods return the invocant, so you can chain them.|
|unmock( $methodname )||Removes any active mocking of the named method. This means any calls to that method will hit the method of that name in the class being mocked, if it exists. This method returns the invocant, you can chain it.|
|isa( $class )||As youd expect from a mocked object, this will return true for the class its mocking.|
To do its magic, this module uses several internal methods:
o check_class_loaded( $parent_class )
This verifies that you have the mockee defined. If not, it attempts to load the corresponding module for you.
o gen_autoload( $extended )
Returns an AUTOLOAD subroutine for the mock object that checks that the extended object (or class) can perform the requested method, that Test::MockObject can perform it, or that the parent has an appropriate AUTOLOAD of its own. (It should have its own can() in that case too though.)
o gen_can( $extended )
Returns a can() method for the mock object that respects the same execution order as gen_autoload().
o gen_isa( $extended )
Returns an isa() method for the mock object that claims to be the $extended object appropriately.
o gen_get_parents( $extended )
Returns a __get_parents() method for the mock object that claims to be the $extended object appropriately.
o gen_package( $extended )
Creates a new unique package for the mock object with the appropriate methods already installed.
o get_class( $invocant )
Returns the class name of the invocant, whether its an object or a class name.
There may be some weird corner cases with dynamically generated methods in the mocked class. You really should use subroutine declarations though, or at least set can() appropriately.
There are also potential name collisions with methods in this module or Test::MockObject, though this should be rare.
chromatic, <chromatic at wgz dot org>
Documentation bug fixed by Stevan Little. Additional AUTOLOAD approach suggested by Adam Kennedy. Field-based objects supported by Gavin Mogan. Other bugs reported by Paul the Nomad and Praveen Ray. Thank you all!
No known bugs.
Copyright (c) 2004 - 2014, chromatic. All rights reserved. You may use, modify, and distribute this module under the same terms as Perl 5.10
|perl v5.20.3||TEST::MOCKOBJECT::EXTENDS (3)||2015-05-27|