Test::Builder::Mock::Class::Role::Object - Role for base object of mock class


Test-Builder-Mock-Class documentation Contained in the Test-Builder-Mock-Class distribution.

Index


Code Index:

NAME

Top

Test::Builder::Mock::Class::Role::Object - Role for base object of mock class

DESCRIPTION

Top

This role provides an API for changing behavior of mock class.

INHERITANCE

Top

ATTRIBUTES

Top

_mock_test_builder : Test::Builder

The Test::Builder singleton object.

METHODS

Top

mock_tally() : Self

Check the expectations at the end. See Test::Mock::Class::Role::Object for more description.

The test passes if original mock_tally method doesn't throw an exception.

mock_invoke( method : Str, args : Array ) : Any

Returns the expected value for the method name and checks expectations. See Test::Mock::Class::Role::Object for more description.

The test passes if original mock_tally method doesn't throw an exception.

SEE ALSO

Top

Test::Mock::Class::Role::Object, Test::Mock::Class.

BUGS

Top

The API is not stable yet and can be changed in future.

AUTHOR

Top

Piotr Roszatycki <dexter@cpan.org>

LICENSE

Top

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.


Test-Builder-Mock-Class documentation Contained in the Test-Builder-Mock-Class distribution.
#!/usr/bin/perl -c

package Test::Builder::Mock::Class::Role::Object;

use 5.006;

use strict;
use warnings;

our $VERSION = '0.0203';

use Moose::Role 0.89;


with 'Test::Mock::Class::Role::Object' => {
    -alias => {
        mock_invoke => '_mock_invoke_base',
        mock_tally  => '_mock_tally_base',
    },
    -excludes => [ 'mock_invoke', 'mock_tally' ],
};


use English '-no_match_vars';

use Test::Builder;


use Exception::Base (
    '+ignore_package' => [__PACKAGE__],
);


has '_mock_test_builder' => (
    is      => 'rw',
    default => sub { Test::Builder->new },
);


use namespace::clean -except => 'meta';


## no critic qw(RequireCheckingReturnValueOfEval)

sub mock_tally {
    my ($self) = @_;

    my $return = eval {
        $self->_mock_tally_base;
    };
    $self->_mock_test_builder->is_eq($EVAL_ERROR, '', 'mock_tally()');

    return $return;
};


sub mock_invoke {
    my ($self, $method, @args) = @_;

    my ($return, @return);
    eval {
        if (wantarray) {
            @return = $self->_mock_invoke_base($method, @args);
        }
        else {
            $return = $self->_mock_invoke_base($method, @args);
        };
    };
    $self->_mock_test_builder->is_eq($EVAL_ERROR, '', "mock_invoke($method)");

    return wantarray ? @return : $return;
};


1;