jeudi 24 septembre 2015

Unit test: Simulate a timeout with Guzzle 5

I am using Guzzle 5.3 and want to test that my client throws a TimeOutException.

Then, How can I do a mock of Guzzle Client that throw a GuzzleHttp\Exception\ConnectException?

Code to test.

try {
    /** @noinspection PhpVoidFunctionResultUsedInspection */
    /** @var \GuzzleHttp\Message\ResponseInterface $response */
    $response =  $this->httpClient->post($path, ['body' => $requestData]);
} catch (ConnectException $e) {
    throw new Vendor\Client\TimeOutException();
}

Aucun commentaire:

Enregistrer un commentaire