vendredi 30 janvier 2015

perl Test::Mock() how to return both a value and a function in a mockObject?

So I'm mocking results that I get back from a service call (I can't change the format of these results btw). In one case a call to getValue() returns an array of objects, but getValue()->getType() returns a string indicating what type of array I got.


Can anybody help me with how to mock this with a mockObject? I don't know how to make the mockObject both mock a method or return a value, this is what I have so far, obviously this won't work but I'm flumoxed as to how to get it to do what I need:



my $service;
my $mockService = sub {
my (@values) = @_;
$service = mockModule(
'Some::Service',
getValue => createMockObject (
return \@values;
getType => 'mytype'; #???
)
)
};


This is related to my other question -- I'm having a tough time mocking this particular aspect of this rather complex service!


Aucun commentaire:

Enregistrer un commentaire