I'm attempting to make a unit test for perl code to mock a service which returns an array containing objects which also need to be mocked because they have a method getType() which I need to mock.
So the code which processes the results of this service call looks something like this:
foreach my $set (@{$serviceResults->getValue()}) {
next unless ($set->getType() eq 'type');
...
}
and I'm trying to mock the service like so:
my $service;
my $mockService = sub {
my (%resultValues) = @_;
$service = mockModule(
'My::Service',
getValue => createMockObject(
# how to mock the getType method?
)
)
};
And then I create a mock like this:
$mockService->([
{type=>'a', data=>[0, 5]},
{type=>'b', data=>[2, 3]}]);
So how do I create the mock of the getType method on each hash object in the array? This array changes depending on the unit test, I can't use a fixed size array.
Aucun commentaire:
Enregistrer un commentaire