Looking at the Guzzel tests on how they tested pool doesn't help me because they test pool its self. And I don't want to test pool per say I want to test that the way I am using it actually works.
Consider the following:
public function getItemHistoryForRegion(array $items, array $regions) {
$acceptedResponses = [];
$this->createRequests($items, $regions);
$pool = new Pool($this->client, $this->createdRequests, [
'concurrency' => 18,
'fulfilled' => function ($response, $index) use (&$acceptedResponses) {
$responseJson = json_decode($response->getBody()->getContents());
$acceptedResponses[$index] = $responseJson;
$this->populateHistoricalDataContainer($responseJson, $acceptedResponses);
},
'rejected' => function ($reason, $index) use(&$rejectedResponses) {
$this->eveLogHandler->messageLog($reason, 'eve_online_region_item_history_rejected_responses.log');
},
]);
$promise = $pool->promise();
$promise->wait();
return end($this->historicalData);
}
We have a series of requests that are created based on the items and regions. We then have a pool object that is created and turned into a promise which we wait on.
in side the fulfilled portion of the pool we populate a container with some information that come back from the response.
I feel like I can remove the $this->createRequests($items, $regions); and the method call inside the fulfilled section as well as the end return statement and put that in its own method.
This then allows me to test all the functionality out side of this method.
But that still leaves me with the Pool. How do I the method? Do I? I mean once I remove everything then I am left with this:
public function getItemHistoryForRegion() {
$acceptedResponses = [];
$pool = new Pool($this->client, $this->createdRequests, [
'concurrency' => 18,
'fulfilled' => function ($response, $index) use (&$acceptedResponses) {
$responseJson = json_decode($response->getBody()->getContents());
$acceptedResponses[$index] = $responseJson;
},
'rejected' => function ($reason, $index) use(&$rejectedResponses) {
$this->eveLogHandler->messageLog($reason, 'eve_online_region_item_history_rejected_responses.log');
},
]);
$promise = $pool->promise();
$promise->wait();
return $acceptedResponses
}
Which is much better and cleaner. But how do I test the method? I don't even know where to begin. Does any one use Pool in there code bases for those who use guzzel? If so how do you test this?
The only thing I an think to do is mock the method but then once I mock it Im not really testing it ...
I could Create a method wrapper for the function and then call that function and mock this function and do a "I expect this function to be called once and to return me an array of x" But that just tests that the function name is spelled properly and that it was called. not that it fetched data and actually returns me something.
The other issue I don't want it to actually hit any api services I just want to make sure that when it runs I get an array of accepted response. Should I do the method wrapper and mocking concept? Is that even "best practices"??
Im at a loss here. Help?
Aucun commentaire:
Enregistrer un commentaire