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.
public function request($namedRoute, $data = [])
{
try {
/** @noinspection PhpVoidFunctionResultUsedInspection */
/** @var \GuzzleHttp\Message\ResponseInterface $response */
$response = $this->httpClient->post($path, ['body' => $requestData]);
} catch (ConnectException $e) {
throw new \Vendor\Client\TimeOutException();
}
}
Update:
The right question was: how to throw a Exception with Guzzle 5? or, how to test a catch block with Guzzle 5?