mercredi 22 juin 2016

Testing Guzzle 6 Download Progress

I'm having trouble triggering the 'progress' callback during testing.

Here is the code to be tested:

    $this->guzzleClient->request(
        'GET',
        'http://ift.tt/28NFdcN',
        [
            '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.

Aucun commentaire:

Enregistrer un commentaire