我正在使用Guzzle 5.3,并想测试我的客户端抛出一个TimeOutException.
然后,我怎么能模拟Guzzle客户端抛出一个GuzzleHttp\Exception\ConnectException?
要测试的代码.
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();
}
}
Run Code Online (Sandbox Code Playgroud)
更新:
正确的问题是:如何使用Guzzle 5抛出异常?或者,如何用Guzzle 5测试一个挡块?
我在Haskell编程,我遇到以下代码的问题:
exactRootList :: Int -> Int -> [Int]
exactRootList ini end =
[x | x<-[ini .. end], (floor (sqrt x)) == (ceiling (sqrt x))]
Run Code Online (Sandbox Code Playgroud)
然后,当我执行时:
> hugs myprogram.hs
Run Code Online (Sandbox Code Playgroud)
我明白了
Error Instances of (Floating Int, RealFrac Int) required for definition of exactRootList
Run Code Online (Sandbox Code Playgroud)
我不明白这个错误.
我的程序应该在区间[a,b]上显示具有精确根4或9的数字列表,其中a和b是函数的两个参数.例:
exactRootList 1 10
Run Code Online (Sandbox Code Playgroud)
它必须回归
1 4 9
Run Code Online (Sandbox Code Playgroud)
因为1到10之间只有1,4和9具有确切的根.
问候!