-
Notifications
You must be signed in to change notification settings - Fork 39
Closed
Description
Q | A |
---|---|
Bug? | yes |
New Feature? | no |
Version | 1c63817 |
Actual Behavior
When trying to test an async request with a callable for onFulfilled
, if this callable returns something different to a ResponseInterface
will fail.
For example, we are using the Promise fullfilled callable to check the response is status code 200 and then convert the received body to another object and returns the other object.
Expected Behavior
The constructor must accept mixed content, not only ResponseInterface
subclasses.
Steps to Reproduce
- Create a Client mock and a ResponseInterface mock, then and the response mock to the client mock.
- Call
sendAsyncRequest
, this method should return aPromise
, then call methodthen
with a anonymous function foronFullfilled
parameter. - The anonymous function should return something different to
ResponseInterface
.
return $response->then(
function (ResponseInterface $response) use ($request) {
if (200 <= $response->getStatusCode() && $response->getStatusCode() < 300) {
return 'success';
}
return 'fail';
}
);
* This is just an example, in our case, we are deserializing a response body with is a JSON
to an object and returning this object.
Possible Solutions
Change the constructor definition to allow mixed data.
<?php
namespace Http\Client\Promise;
//...
final class HttpFulfilledPromise implements Promise
{
// ...
/**
* @param ResponseInterface $response
*/
public function __construct($response)
{
$this->response = $response;
}
// ...
Metadata
Metadata
Assignees
Labels
No labels