Test::Mockify::ReturnValue - To define return values
Use Test::Modify::ReturnValue to define different types of return values. See method description for more details.
my $ReturnValue = Test::Mockify::ReturnValue->new();
The new method creates a new return value object.
new
my $ReturnValue = Test::Mockify::ReturnValue->new(); $ReturnValue->thenReturn('Hello World'); my $Result = $ReturnValue->call(); is($Result, 'Hello World'); =head3 Options
The thenReturn method set the return value of call.
thenReturn
call
my $ReturnValue = Test::Mockify::ReturnValue->new(); $ReturnValue->thenReturnArray([1,23]); my @Result = $ReturnValue->call(); is_deeply(\@Result, [1,23]); =head3 Options
The thenReturnArray method sets the return value of call in the way that it will return an Array.
thenReturnArray
my $ReturnValue = Test::Mockify::ReturnValue->new(); $ReturnValue->thenReturnHash({1 => 23}); my %Result = $ReturnValue->call(); is_deeply(\%Result, {1 => 23}); =head3 Options
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->thenReturnUndef(); my $Result = $ReturnValue->call(); is($Result, undef); =head3 Options
The thenReturnArray method sets the return value of call in the way that it will return undef.
my $ReturnValue = Test::Mockify::ReturnValue->new(); $ReturnValue->thenThrowError('ErrorType'); throws_ok( sub { $ReturnValue->call() }, qr/ErrorType/, ); =head3 Options
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->thenCall(sub{return join('-', @_);}); my $Result = $ReturnValue->call('hello','world'); is($Result, 'hello-world'); =head3 Options
The thenCall method change the call Function in a way that it will trigger the function and pass in the parameters.
thenCall
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.
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.
Christian Breitkreutz <cbreitkreutz@epages.com>
To install Test::Mockify, copy and paste the appropriate command in to your terminal.
cpanm
cpanm Test::Mockify
CPAN shell
perl -MCPAN -e shell install Test::Mockify
For more information on module installation, please visit the detailed CPAN module installation guide.