samedi 6 février 2016

Mocking Guzzel Client

Consider the following code

    public function getItemHistoryForRegion() {

        $pool = new Pool($this->client, $this->createdRequests, $this->getOptions());

        $promise = $pool->promise();
        $promise->wait();
    }

I need to mock the client such that the response has a body. It cant be a body of foo for all I care.

What I have a for a mock already is:

    $headers = [];

    $handler = new MockHandler([
        function (Request $request) use (&$headers) {
            $headers[] = $request;
            return new Response(
                404, ['Content-Length' => 0]
            );
        }
    ]);

    $client  = new Client(['handler' => $handler]);

How ever when I run this the response that comes back is:

class GuzzleHttp\Psr7\Response#1182 (6) {
  private $reasonPhrase =>
  string(2) "OK"
  private $statusCode =>
  int(200)
  private $headers =>
  array(0) {
  }
  private $headerLines =>
  array(0) {
  }
  private $protocol =>
  string(3) "1.1"
  private $stream =>
  NULL
}

So How do I test this such that I can create a response with any status code and any body?

Aucun commentaire:

Enregistrer un commentaire