File Coverage

blib/lib/Test/Mockify/Parameter.pm
Criterion Covered Total %
statement 44 44 100.0
branch 12 12 100.0
condition 4 4 100.0
subroutine 10 10 100.0
pod 0 5 0.0
total 70 75 93.3


line stmt bran cond sub pod time code
1             package Test::Mockify::Parameter;
2 7     7   21777 use Test::Mockify::ReturnValue;
  7         12  
  7         182  
3 7     7   2886 use Data::Compare;
  7         62106  
  7         52  
4 7     7   22527 use Test::Mockify::TypeTests qw ( IsString );
  7         15  
  7         373  
5              
6 7     7   56 use strict;
  7         8  
  7         132  
7 7     7   27 use warnings;
  7         10  
  7         2319  
8             #---------------------------------------------------------------------
9             sub new {
10 107     107 0 3012     my $class = shift;
11 107         97     my ($ExpectedParams) = @_;
12 107   100     229     $ExpectedParams //= [];
13 107         198     my $self = bless {
14                     'ExpectedParams' => $ExpectedParams,
15                 }, $class;
16 107         182     return $self;
17             }
18             #---------------------------------------------------------------------
19             sub call {
20 86     86 0 150     my $self = shift;
21 86 100       175     die ('NoReturnValueDefined') unless ($self->{'ReturnValue'});
22 85         206     return $self->{'ReturnValue'}->call(@_);
23             }
24             #---------------------------------------------------------------------
25             sub buildReturn {
26 91     91 0 75     my $self = shift;
27 91         238     $self->{'ReturnValue'} = Test::Mockify::ReturnValue->new();
28 91         355     return $self->{'ReturnValue'};
29             }
30             #---------------------------------------------------------------------
31             sub compareExpectedParameters {
32 14     14 0 712     my $self = shift;
33 14         15     my ($Parameters) = @_;
34 14   100     26     $Parameters //= [];
35 14 100       25     return 0 unless (scalar @{$Parameters} == scalar @{$self->{'ExpectedParams'}});
  14         16  
  14         37  
36 11         38     return Data::Compare->new()->Cmp($Parameters, $self->{'ExpectedParams'});
37             }
38             #---------------------------------------------------------------------
39             sub matchWithExpectedParameters {
40 89     89 0 113     my $self = shift;
41 89         108     my @Params = @_;
42 89 100       79     return 0 unless (scalar @Params == scalar @{$self->{'ExpectedParams'}});
  89         191  
43              
44 84         152     for(my $i=0; $i < scalar @Params; $i++){
45 130 100       427         if(not $self->{'ExpectedParams'}->[$i]->{'Value'}){
    100          
    100          
46 61         93             next;
47                     }elsif(ref($Params[$i]) eq $self->{'ExpectedParams'}->[$i]->{'Value'}){# map package name
48 9         26             next;
49                     }elsif(Data::Compare->new()->Cmp($Params[$i], $self->{'ExpectedParams'}->[$i]->{'Value'})){
50 49         2907             next;
51                     } else{
52 11         574             return 0;
53                     }
54                 }
55 73         179     return 1;
56             }
57              
58             1;