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

ReturnValue

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

new

  my $ReturnValue = Test::Mockify::ReturnValue->new();

Options

The new method creates a new return value object.

thenReturn

  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.

thenReturnArray

  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.

thenReturnHash

  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.

thenReturnUndef

  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.

thenThrowError

  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.

thenCall

  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.

call

  my $ReturnValue = Test::Mockify::ReturnValue->new();
  $ReturnValue->thenReturn('Hello World');
  my $Result = $ReturnValue->call();
  is($Result, 'Hello World');
=head3 Options

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.

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 <cbreitkreutz@epages.com>