Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Http::withOptions('sink' => $path) has no effect with Http::fake #33557

Closed
lucaspottersky opened this issue Jul 16, 2020 · 1 comment · Fixed by #33720
Closed

Http::withOptions('sink' => $path) has no effect with Http::fake #33557

lucaspottersky opened this issue Jul 16, 2020 · 1 comment · Fixed by #33720

Comments

@lucaspottersky
Copy link

  • Laravel Version: 7.14.1
  • PHP Version: 7.4.6
  • Database Driver & Version: N/A
  • guzzlehttp/guzzle: 6.5.4

Description:

Trying to create a fake HTTP response that returns a file to Guzzle Http Client. The "sink" option seems to be ignored and no file is created at all.
The below test case fails.

Steps To Reproduce:

    function testFakes() {
        $filepath = __DIR__ . '/test-files/easy-txt.txt';
        $inDiskSize = filesize($filepath);

        $r = Http::response(
            file_get_contents($filepath),
            200,
            [
                'Content-Type' => 'text/plain; charset=UTF-8',
                'Content-Length' => $inDiskSize,
                'Content-Disposition' => 'attachment; filename="cool.html"'
            ]
        );
        Http::fake($r);

        $downloadLocation = '/tmp/downloaded_zip';
        $response = Http::withOptions(
            [
              // ▼▼▼ THE SINK OPTION SEEMS TO HAVE NO EFFECT. ▼▼▼
              RequestOptions::SINK => $downloadLocation
            ]
        )->get('http://foo/my.zip');

        Http::assertSentCount(1);

        // 💣💣💣 FAILS: filesize(): stat failed for /tmp/downloaded_zip
        $this->assertEquals($inDiskSize, filesize($downloadLocation));
    }

Related StackOverflow: https://stackoverflow.com/questions/62926381/laravel-fake-http-response-file-to-guzzle-http-client-sink-stream

@driesvints
Copy link
Member

Seems like a feature request. Feel free to send in a PR if you want.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants