Skip to content

HttpFulfilledPromise constructor parameter should be mixed #123

@aferrandini

Description

@aferrandini
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

  1. Create a Client mock and a ResponseInterface mock, then and the response mock to the client mock.
  2. Call sendAsyncRequest, this method should return a Promise, then call method then with a anonymous function for onFullfilled parameter.
  3. 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

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions