Skip to content

Commit 36d783c

Browse files
committed
fix with cookies
1 parent b93848b commit 36d783c

File tree

2 files changed

+23
-3
lines changed

2 files changed

+23
-3
lines changed

src/Illuminate/Http/Client/PendingRequest.php

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
namespace Illuminate\Http\Client;
44

55
use GuzzleHttp\Client;
6+
use GuzzleHttp\Cookie\CookieJar;
67
use GuzzleHttp\Exception\ConnectException;
78
use GuzzleHttp\HandlerStack;
89
use Illuminate\Support\Traits\Macroable;
@@ -285,13 +286,14 @@ public function withToken($token, $type = 'Bearer')
285286
* Specify the cookies that should be included with the request.
286287
*
287288
* @param array $cookies
289+
* @param string $domain
288290
* @return $this
289291
*/
290-
public function withCookies(array $cookies)
292+
public function withCookies(array $cookies, string $domain)
291293
{
292-
return tap($this, function ($request) use ($cookies) {
294+
return tap($this, function ($request) use ($cookies, $domain) {
293295
return $this->options = array_merge_recursive($this->options, [
294-
'cookies' => $cookies,
296+
'cookies' => CookieJar::fromArray($cookies, $domain),
295297
]);
296298
});
297299
}

tests/Http/HttpClientTest.php

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -193,4 +193,22 @@ public function testFakeSequence()
193193
$this->assertSame(201, $this->factory->get('https://example.com')->status());
194194
$this->assertSame(301, $this->factory->get('https://example.com')->status());
195195
}
196+
197+
public function testWithCookies()
198+
{
199+
$this->factory->fakeSequence()->pushStatus(200);
200+
201+
$response = $this->factory->withCookies(
202+
['foo' => 'bar'], 'https://laravel.com'
203+
)->get('https://laravel.com');
204+
205+
$this->assertCount(1, $response->cookies()->toArray());
206+
207+
/** @var CookieJarInterface $responseCookies */
208+
$responseCookie = $response->cookies()->toArray()[0];
209+
210+
$this->assertSame('foo', $responseCookie['Name']);
211+
$this->assertSame('bar', $responseCookie['Value']);
212+
$this->assertSame('https://laravel.com', $responseCookie['Domain']);
213+
}
196214
}

0 commit comments

Comments
 (0)