Skip to content

Commit

Permalink
fix with cookies
Browse files Browse the repository at this point in the history
  • Loading branch information
taylorotwell committed Mar 4, 2020
1 parent b93848b commit 36d783c
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 3 deletions.
8 changes: 5 additions & 3 deletions src/Illuminate/Http/Client/PendingRequest.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
namespace Illuminate\Http\Client;

use GuzzleHttp\Client;
use GuzzleHttp\Cookie\CookieJar;
use GuzzleHttp\Exception\ConnectException;
use GuzzleHttp\HandlerStack;
use Illuminate\Support\Traits\Macroable;
Expand Down Expand Up @@ -285,13 +286,14 @@ public function withToken($token, $type = 'Bearer')
* Specify the cookies that should be included with the request.
*
* @param array $cookies
* @param string $domain
* @return $this
*/
public function withCookies(array $cookies)
public function withCookies(array $cookies, string $domain)
{
return tap($this, function ($request) use ($cookies) {
return tap($this, function ($request) use ($cookies, $domain) {
return $this->options = array_merge_recursive($this->options, [
'cookies' => $cookies,
'cookies' => CookieJar::fromArray($cookies, $domain),
]);
});
}
Expand Down
18 changes: 18 additions & 0 deletions tests/Http/HttpClientTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -193,4 +193,22 @@ public function testFakeSequence()
$this->assertSame(201, $this->factory->get('https://example.com')->status());
$this->assertSame(301, $this->factory->get('https://example.com')->status());
}

public function testWithCookies()
{
$this->factory->fakeSequence()->pushStatus(200);

$response = $this->factory->withCookies(
['foo' => 'bar'], 'https://laravel.com'
)->get('https://laravel.com');

$this->assertCount(1, $response->cookies()->toArray());

/** @var CookieJarInterface $responseCookies */
$responseCookie = $response->cookies()->toArray()[0];

$this->assertSame('foo', $responseCookie['Name']);
$this->assertSame('bar', $responseCookie['Value']);
$this->assertSame('https://laravel.com', $responseCookie['Domain']);
}
}

0 comments on commit 36d783c

Please sign in to comment.