guzzler icon indicating copy to clipboard operation
guzzler copied to clipboard

More examples

Open oxodao opened this issue 3 years ago • 1 comments

Hi!

I've seen this issue being closed while there are still quite a few places in the docs that do not have examples https://github.com/blastcloud/guzzler/issues/3

Do you plan to add those ?

Particularly, I took quite a while to figure out how to test multi-part forms that contains file, as I was trying to use the withBody method combined with a MultipartStream object.

My final solution here is the following, if anyone have the same needs:

$filepath = dirname(__FILE__) . '/../assets/asset1.jpg';
$this->guzzler
    ->expects($this->once())
    ->post('/assets/')
    ->withHeader('Authorization', 'Bearer ' . $this->fakeToken)
    ->withForm([
          'my_field_1' => 1,
          'my_field_2' => 'my_value',
     ])
     ->withFile('file', new File(Utils::tryFopen($filepath, 'r')))
     ->willRespond(new Response(409, [], ''));

oxodao avatar Apr 01 '22 13:04 oxodao

Hi @oxodao,

I'm sorry for not responding weeks earlier. Life has gotten in the way of working on this project and it's primarily been on the back-burner. For some time I've wanted to update the documentation from being built in VuePress to switch to Jigsaw instead.

I'm glad you found a solution, though.

If you feel up to it, I always welcome Pull Requests. And thanks for using the package.

adamkelso avatar Apr 19 '22 08:04 adamkelso