NAME
Test::Mock::Class::Role::Meta::Class - Metaclass for mock class
DESCRIPTION
This role provides an API for defining and changing behavior of mock class.
ATTRIBUTES
- mock_base_object_role : Str = "Test::Mock::Class::Role::Object"
-
Base object role for mock class. The default is Test::Mock::Class::Role::Object.
- mock_ignore_methods_regexp : RegexpRef = "/^(_?mock_|(can|DEMOLISHALL|DESTROY|DOES|does|isa|VERSION)$)/"
-
Regexp matches method names which are not created automatically for mock class.
- mock_constructor_methods_regexp : RegexpRef = "/^new$/"
-
Regexp matches method names which are constructors rather than normal methods.
CONSTRUCTORS
- create_mock_class( name : Str, :class : Str, args : Hash ) : Moose::Meta::Class
-
Creates new Moose::Meta::Class object which represents named mock class. It automatically adds all methods which exists in original class, except those which matches
mock_ignore_methods_regexp
attribute.If
new
method exists in original class, it is created as constructor.The method takes additional arguments:
- class
-
Optional class parameter is a name of original class and its methods will be created for new mock class.
- methods
-
List of additional methods to create.
The constructor returns metaclass object.
Test::Mock::Class->create_mock_class( 'IO::File::Mock' => ( class => 'IO::File' ) );
- create_mock_anon_class( :class : Str, args : Hash ) : Moose::Meta::Class
-
Creates new Moose::Meta::Class object which represents anonymous mock class. Optional class parameter is a name of original class and its methods will be created for new mock class.
Anonymous classes are destroyed once the metaclass they are attached to goes out of scope.
The constructor returns metaclass object.
my $meta = Test::Mock::Class->create_mock_anon_class( class => 'File::Temp' );
METHODS
- add_mock_method( method : Str ) : Self
-
Adds new method to mock class. The behavior of this method can be changed with
mock_return
and other methods. - add_mock_constructor( method : Str ) : Self
-
Adds new constructor to mock class. This is almost the same as
add_mock_method
but it returns new object rather than defined value.The calls counter is set to
1
for new object's constructor. - _construct_mock_class( :class : Str, :methods : ArrayRef ) : Self
-
Constructs mock class based on original class. Adds the same methods as in original class. If original class has
new
method, the constructor with this name is created.
SEE ALSO
BUGS
The API is not stable yet and can be changed in future.
AUTHOR
Piotr Roszatycki <dexter@cpan.org>
LICENSE
Based on SimpleTest, an open source unit test framework for the PHP programming language, created by Marcus Baker, Jason Sweat, Travis Swicegood, Perrick Penet and Edward Z. Yang.
Copyright (c) 2009, 2010 Piotr Roszatycki <dexter@cpan.org>.
This program is free software; you can redistribute it and/or modify it under GNU Lesser General Public License.