From 867856e1f4091a19a821c42a7e2d828a464a14f2 Mon Sep 17 00:00:00 2001 From: Sjors Ottjes Date: Wed, 4 Mar 2020 20:04:41 +0100 Subject: [PATCH 1/5] fix with cookies --- src/Illuminate/Http/Client/PendingRequest.php | 5 +++-- src/Illuminate/Support/Facades/Http.php | 3 ++- tests/Http/HttpClientTest.php | 18 ++++++++++++++++++ 3 files changed, 23 insertions(+), 3 deletions(-) diff --git a/src/Illuminate/Http/Client/PendingRequest.php b/src/Illuminate/Http/Client/PendingRequest.php index 3b590d6251fa..6e435285034d 100644 --- a/src/Illuminate/Http/Client/PendingRequest.php +++ b/src/Illuminate/Http/Client/PendingRequest.php @@ -3,6 +3,7 @@ namespace Illuminate\Http\Client; use GuzzleHttp\Client; +use GuzzleHttp\Cookie\CookieJarInterface; use GuzzleHttp\Exception\ConnectException; use GuzzleHttp\HandlerStack; use Illuminate\Support\Traits\Macroable; @@ -284,10 +285,10 @@ public function withToken($token, $type = 'Bearer') /** * Specify the cookies that should be included with the request. * - * @param array $cookies + * @param \GuzzleHttp\Cookie\CookieJarInterface $cookies * @return $this */ - public function withCookies(array $cookies) + public function withCookies(CookieJarInterface $cookies) { return tap($this, function ($request) use ($cookies) { return $this->options = array_merge_recursive($this->options, [ diff --git a/src/Illuminate/Support/Facades/Http.php b/src/Illuminate/Support/Facades/Http.php index 5a8e4eafc203..1f6a05943106 100644 --- a/src/Illuminate/Support/Facades/Http.php +++ b/src/Illuminate/Support/Facades/Http.php @@ -2,6 +2,7 @@ namespace Illuminate\Support\Facades; +use GuzzleHttp\Cookie\CookieJarInterface; use Illuminate\Http\Client\Factory; /** @@ -18,7 +19,7 @@ * @method static \Illuminate\Http\Client\PendingRequest withBasicAuth(string $username, string $password) * @method static \Illuminate\Http\Client\PendingRequest withDigestAuth(string $username, string $password) * @method static \Illuminate\Http\Client\PendingRequest withToken(string $token, string $type = 'Bearer') - * @method static \Illuminate\Http\Client\PendingRequest withCookies(array $cookies) + * @method static \Illuminate\Http\Client\PendingRequest withCookies(CookieJarInterface $cookies) * @method static \Illuminate\Http\Client\PendingRequest withoutRedirecting() * @method static \Illuminate\Http\Client\PendingRequest withoutVerifying() * @method static \Illuminate\Http\Client\PendingRequest timeout(int $seconds) diff --git a/tests/Http/HttpClientTest.php b/tests/Http/HttpClientTest.php index 051132ca5bd5..957129bb4a98 100644 --- a/tests/Http/HttpClientTest.php +++ b/tests/Http/HttpClientTest.php @@ -2,6 +2,8 @@ namespace Illuminate\Tests\Http; +use GuzzleHttp\Cookie\CookieJar; +use GuzzleHttp\Cookie\CookieJarInterface; use Illuminate\Http\Client\Factory; use Illuminate\Http\Client\PendingRequest; use Illuminate\Http\Client\Request; @@ -193,4 +195,20 @@ 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( + CookieJar::fromArray(['foo' => 'bar'], 'https://laravel.com') + )->get('https://laravel.com'); + + /** @var CookieJarInterface $responseCookies */ + $responseCookies = $response->cookies(); + + $this->assertSame('foo', $responseCookies->toArray()[0]['Name']); + $this->assertSame('bar', $responseCookies->toArray()[0]['Value']); + $this->assertSame('https://laravel.com', $responseCookies->toArray()[0]['Domain']); + } } From 1509f6657df90695bf4105a159e761095a06a8af Mon Sep 17 00:00:00 2001 From: Sjors Ottjes Date: Wed, 4 Mar 2020 20:09:42 +0100 Subject: [PATCH 2/5] wip --- tests/Http/HttpClientTest.php | 10 ++++++---- 1 file changed, 6 insertions(+), 4 deletions(-) diff --git a/tests/Http/HttpClientTest.php b/tests/Http/HttpClientTest.php index 957129bb4a98..24ed41e8e8a1 100644 --- a/tests/Http/HttpClientTest.php +++ b/tests/Http/HttpClientTest.php @@ -204,11 +204,13 @@ public function testWithCookies() CookieJar::fromArray(['foo' => 'bar'], 'https://laravel.com') )->get('https://laravel.com'); + $this->assertCount(1, $response->cookies()->toArray()); + /** @var CookieJarInterface $responseCookies */ - $responseCookies = $response->cookies(); + $responseCookie = $response->cookies()->toArray()[0]; - $this->assertSame('foo', $responseCookies->toArray()[0]['Name']); - $this->assertSame('bar', $responseCookies->toArray()[0]['Value']); - $this->assertSame('https://laravel.com', $responseCookies->toArray()[0]['Domain']); + $this->assertSame('foo', $responseCookie['Name']); + $this->assertSame('bar', $responseCookie['Value']); + $this->assertSame('https://laravel.com', $responseCookie['Domain']); } } From 5a40dd683e04f34145b38f30c0667b8c01c35a99 Mon Sep 17 00:00:00 2001 From: Sjors Ottjes Date: Wed, 4 Mar 2020 21:06:25 +0100 Subject: [PATCH 3/5] bump lowest required guzzle version --- composer.json | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/composer.json b/composer.json index 52920554dd47..2bf7e5910c65 100644 --- a/composer.json +++ b/composer.json @@ -79,7 +79,7 @@ "aws/aws-sdk-php": "^3.0", "doctrine/dbal": "^2.6", "filp/whoops": "^2.4", - "guzzlehttp/guzzle": "^6.3|^7.0", + "guzzlehttp/guzzle": "^6.3.1|^7.0", "league/flysystem-cached-adapter": "^1.0", "mockery/mockery": "^1.3.1", "moontoast/math": "^1.1", @@ -124,7 +124,7 @@ "doctrine/dbal": "Required to rename columns and drop SQLite columns (^2.6).", "filp/whoops": "Required for friendly error pages in development (^2.4).", "fzaninotto/faker": "Required to use the eloquent factory builder (^1.9.1).", - "guzzlehttp/guzzle": "Required to use the HTTP Client, Mailgun mail driver and the ping methods on schedules (^6.3|^7.0).", + "guzzlehttp/guzzle": "Required to use the HTTP Client, Mailgun mail driver and the ping methods on schedules (^6.3.1|^7.0).", "laravel/tinker": "Required to use the tinker console command (^2.0).", "league/flysystem-aws-s3-v3": "Required to use the Flysystem S3 driver (^1.0).", "league/flysystem-cached-adapter": "Required to use the Flysystem cache (^1.0).", From b1fd467e75bbbe236ab0e4d6d66e5c661086eb01 Mon Sep 17 00:00:00 2001 From: Sjors Ottjes Date: Wed, 4 Mar 2020 21:11:11 +0100 Subject: [PATCH 4/5] bump all versions of guzzle --- src/Illuminate/Console/composer.json | 2 +- src/Illuminate/Mail/composer.json | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/src/Illuminate/Console/composer.json b/src/Illuminate/Console/composer.json index 4ea95ddf29b5..181dc9ea44b9 100755 --- a/src/Illuminate/Console/composer.json +++ b/src/Illuminate/Console/composer.json @@ -32,7 +32,7 @@ }, "suggest": { "dragonmantank/cron-expression": "Required to use scheduling component (^2.0).", - "guzzlehttp/guzzle": "Required to use the ping methods on schedules (^6.3|^7.0).", + "guzzlehttp/guzzle": "Required to use the ping methods on schedules (^6.3.1|^7.0).", "illuminate/filesystem": "Required to use the generator command (^7.0)" }, "config": { diff --git a/src/Illuminate/Mail/composer.json b/src/Illuminate/Mail/composer.json index fbefed3fb50d..706a8c039bcf 100755 --- a/src/Illuminate/Mail/composer.json +++ b/src/Illuminate/Mail/composer.json @@ -36,7 +36,7 @@ }, "suggest": { "aws/aws-sdk-php": "Required to use the SES mail driver (^3.0).", - "guzzlehttp/guzzle": "Required to use the Mailgun mail driver (^6.3|^7.0).", + "guzzlehttp/guzzle": "Required to use the Mailgun mail driver (^6.3.1|^7.0).", "wildbit/swiftmailer-postmark": "Required to use Postmark mail driver (^3.0)." }, "config": { From 3337e9e4e8dc6703bff8725d1da309d175b2e81e Mon Sep 17 00:00:00 2001 From: Graham Campbell Date: Wed, 4 Mar 2020 20:12:45 +0000 Subject: [PATCH 5/5] Added missing suggest --- src/Illuminate/Http/composer.json | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/src/Illuminate/Http/composer.json b/src/Illuminate/Http/composer.json index 68aaa6b8319b..6f6184bd0e4e 100755 --- a/src/Illuminate/Http/composer.json +++ b/src/Illuminate/Http/composer.json @@ -28,7 +28,8 @@ } }, "suggest": { - "ext-gd": "Required to use Illuminate\\Http\\Testing\\FileFactory::image()." + "ext-gd": "Required to use Illuminate\\Http\\Testing\\FileFactory::image().", + "guzzlehttp/guzzle": "Required to use the HTTP Client (^6.3.1|^7.0)." }, "extra": { "branch-alias": {