我在测试期间无法触发“进度”回调。
这是要测试的代码:
$this->guzzleClient->request(
'GET',
'http://example.com/somefile.csv',
[
'sink' => $this->directory . $this->filename . '.csv',
'progress' => function ($download_size, $downloaded, $upload_size, $uploaded) {
$this->downloadProgress($download_size, $downloaded, $upload_size, $uploaded);
},
]);
我能够模拟响应并保存文件,但它永远不会触发“进度”。注意:我使用的响应选项与我从实时服务器获得的响应选项相同。
$mock = new MockHandler([
new Response(
'206',
[
'content-type' => 'application/octet-stream',
'Content-Range' => 'bytes 1113-1113/11591523',
],
new Stream(fopen(__DIR__ . '/test_stream_file.txt', 'r'))
)
]);
$handler = HandlerStack::create($mock);
$client = new Client(['handler' => $handler()]);
我正在考虑仅测试模拟文件的下载,然后downloadProgress
如果这是我唯一的选择,则单独测试该方法。