Name
Test::Mockify::ReturnValue - To define return values
DESCRIPTION
Use Test::Modify::ReturnValue to define different types of return values. See method description for more details.
METHODS
thenReturn
The thenReturn method set the return value of call.
my $ReturnValue = Test::Mockify::ReturnValue->new();
$ReturnValue->thenReturn('Hello World');
my $Result = $ReturnValue->call();
is($Result, 'Hello World');
thenReturnArray
The thenReturnArray method sets the return value of call in the way that it will return an Array.
my $ReturnValue = Test::Mockify::ReturnValue->new();
$ReturnValue->thenReturnArray([1,23]);
my @Result = $ReturnValue->call();
is_deeply(\@Result, [1,23]);
thenReturnHash
The thenReturnArray method sets the return value of call in the way that it will return a Hash.
my $ReturnValue = Test::Mockify::ReturnValue->new();
$ReturnValue->thenReturnHash({1 => 23});
my %Result = $ReturnValue->call();
is_deeply(\%Result, {1 => 23});
thenReturnUndef
The thenReturnArray method sets the return value of call in the way that it will return undef.
my $ReturnValue = Test::Mockify::ReturnValue->new();
$ReturnValue->thenReturnUndef();
my $Result = $ReturnValue->call();
is($Result, undef);
thenThrowError
The thenReturnArray method sets the return value of call in the way that it will create an error.
my $ReturnValue = Test::Mockify::ReturnValue->new();
$ReturnValue->thenThrowError('ErrorType');
throws_ok( sub { $ReturnValue->call() }, qr/ErrorType/, );
thenCall
The thenCall method change the call Function in a way that it will trigger the function and pass in the parameters.
my $ReturnValue = Test::Mockify::ReturnValue->new();
$ReturnValue->thenCall(sub{return join('-', @_);});
my $Result = $ReturnValue->call('hello','world');
is($Result, 'hello-world');
call
The call method will return the return value which was set with one of the setter methods likethenReturn. In case of thenCall it will also forward the parameters. It will throw an error if one of the setter methods was not called at least once.
my $ReturnValue = Test::Mockify::ReturnValue->new();
$ReturnValue->thenReturn('Hello World');
my $Result = $ReturnValue->call();
is($Result, 'Hello World');
LICENSE
Copyright (C) 2017 ePages GmbH
This library is free software; you can redistribute it and/or modify it under the same terms as Perl itself.
AUTHOR
Christian Breitkreutz <christianbreitkreutz@gmx.de>