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

[7.x] Fix Http::withCookies() #31745

Closed
wants to merge 5 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
4 changes: 2 additions & 2 deletions composer.json
Expand Up @@ -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",
Expand Down Expand Up @@ -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).",
Expand Down
2 changes: 1 addition & 1 deletion src/Illuminate/Console/composer.json
Expand Up @@ -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": {
Expand Down
5 changes: 3 additions & 2 deletions src/Illuminate/Http/Client/PendingRequest.php
Expand Up @@ -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;
Expand Down Expand Up @@ -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, [
Expand Down
3 changes: 2 additions & 1 deletion src/Illuminate/Http/composer.json
Expand Up @@ -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": {
Expand Down
2 changes: 1 addition & 1 deletion src/Illuminate/Mail/composer.json
Expand Up @@ -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": {
Expand Down
3 changes: 2 additions & 1 deletion src/Illuminate/Support/Facades/Http.php
Expand Up @@ -2,6 +2,7 @@

namespace Illuminate\Support\Facades;

use GuzzleHttp\Cookie\CookieJarInterface;
use Illuminate\Http\Client\Factory;

/**
Expand All @@ -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)
Expand Down
20 changes: 20 additions & 0 deletions tests/Http/HttpClientTest.php
Expand Up @@ -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;
Expand Down Expand Up @@ -193,4 +195,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(
CookieJar::fromArray(['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']);
}
}