Reputation: 129
I'm having trouble triggering the 'progress' callback during testing.
Here is the code to be tested:
$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);
},
]);
I'm able to mock a response and it saves the file, but it never triggers 'progress'. Note: The response options I'm using are the same as the ones I get from the live server.
$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()]);
I'm considering just testing that the mock file downloads and then testing the downloadProgress
method separately if that's my only option.
Upvotes: 1
Views: 745
Reputation: 2047
The MockHandler does not implement the 'progress' request option.
Testing of the handlers ability to fire the progress callback would be duplication of the Guzzle test suite. Specifically:
If your goal is to test to ensure that the callback performs intended operations, separate that into a different test.
If your goal is to test handler capability, I refer you to the Guzzle Test Suite.
CurlFactory is the default handler for non-Windows systems.
StreamHandler is the default handler for Windows systems.
Upvotes: 1