The Perl Toolchain Summit needs more sponsors. If your company depends on Perl, please support this very important event.

NAME

Test::AutoMock::Manager - Manage Test::AutoMock::Mock::Basic

DESCRIPTION

This module provides an interface for manipulating Test::AutoMock::Mock::Basic and Test::AutoMock::Mock::Overloaded.

METHODS

add_method

    manager($mock)->add_method(add_one => sub { $_[0] + 1 });
    manager($mock)->add_method('path->to->some_obj->name' => 'some_obj');

Define the behavior of AutoMock when calling a method.

The first argument is the method name. You can also specify nested names with ->. A call in the middle of a method chain is regarded as a field and can not be defined as a method at the same time. For example, if you try to specify 'get_object->name' and 'get_object' as the same mock, you'll get an error.

The second argument specifies the return value when the method is called. If you specify a code reference, that code will be called on method invocation. Be aware that neither $mock nor manager($mock) are not included in arguments.

set_isa

    manager($mock)->set_isa('Foo', 'Hoge');

Specify the superclass of the mock. This specification only affects the isa method. It is convenient when argument is checked like Moose field.

child

    # return the manager($mock->some_field)
    manager($mock)->child('some_field');

Return the Manager of the mock's child. Since this call is not recorded, it is convenient when you want to avoid recording unnecessary calls when writing assertions.

TODO: Support -> notations.

mock

It returns the mock that this manager manages. See also Test::AutoMock::manager.

calls

    my @calls = manager($mock)->calls;

Returns all recorded method calls. The element of "calls" is a two-element array-ref. The first element is a method name, and the second element is an array-ref representing arguments.

Method calls to children are also recorded in $mock. For example, calling $mock->child->do_it will record two calls 'child' and 'child->do_it'.

reset

Erase all recorded method calls. Delete all method call history from descendant mocks as well. It is used when you want to reuse mock.

called_ok

    manager($mock)->called_ok('hoge->bar');

Checks if the method was called. It is supposed to be used with Test::More .

called_with_ok

    manager($mock)->called_with_ok(
        'hoge->bar', [10, 20],
    );

Checks if the method was called with specified arguments.

not_called_ok

    manager($mock)->not_called_ok('hoge->bar');

Checks if the method was not called.

LICENSE

Copyright (C) Masahiro Honma.

This library is free software; you can redistribute it and/or modify it under the same terms as Perl itself.

SEE ALSO

Test::AutoMock

AUTHOR

Masahiro Honma <hiratara@cpan.org>