From def93bab139becafc023b65d1aab871d0aa129a0 Mon Sep 17 00:00:00 2001 From: Saransh Dhingra Date: Tue, 14 Sep 2021 22:11:46 +0530 Subject: [PATCH] feat: Upgrade Guzzlehttp/psr7 version (#4508) * Changed the uses of deprecated functions from GuzzleHttp/Psr7 to alternate methods * Changed the use of Psr7\stream_for() to Utils::streamFor in a missed Storage file * Bumped dependency versions of guzzlehttp/psr7, google/auth and google/gax * Bumped psr7 dependency in Core/ * Updated dependencies in Core and the the packages using Psr7 from google/cloud-core * Updated dependency of google/cloud-core in Vision --- composer.json | 6 +++--- src/Blob.php | 4 ++-- src/RequestBuilder.php | 1 - src/RequestWrapper.php | 4 ++-- src/Upload/AbstractUploader.php | 4 ++-- src/Upload/ResumableUploader.php | 1 - src/UriTrait.php | 5 +++-- tests/Unit/Upload/MultipartUploaderTest.php | 7 +++---- tests/Unit/Upload/ResumableUploaderTest.php | 5 ++--- tests/Unit/Upload/SignedUrlUploaderTest.php | 5 ++--- 10 files changed, 19 insertions(+), 23 deletions(-) diff --git a/composer.json b/composer.json index 95d96ab..d0f68f3 100644 --- a/composer.json +++ b/composer.json @@ -6,10 +6,10 @@ "require": { "php": ">=5.5", "rize/uri-template": "~0.3", - "google/auth": "^1.12", + "google/auth": "^1.18", "guzzlehttp/guzzle": "^5.3|^6.0|^7.0", "guzzlehttp/promises": "^1.3", - "guzzlehttp/psr7": "^1.2", + "guzzlehttp/psr7": "^1.7|^2.0", "monolog/monolog": "^1.1|^2.0", "psr/http-message": "1.0.*" }, @@ -18,7 +18,7 @@ "squizlabs/php_codesniffer": "2.*", "phpdocumentor/reflection": "^3.0", "erusev/parsedown": "^1.6", - "google/gax": "^1.1", + "google/gax": "^1.9", "opis/closure": "^3", "google/common-protos": "^1.0" }, diff --git a/src/Blob.php b/src/Blob.php index 665886f..3824f7e 100644 --- a/src/Blob.php +++ b/src/Blob.php @@ -17,7 +17,7 @@ namespace Google\Cloud\Core; -use GuzzleHttp\Psr7; +use GuzzleHttp\Psr7\Utils; use Psr\Http\Message\StreamInterface; /** @@ -52,7 +52,7 @@ class Blob */ public function __construct($value) { - $this->value = Psr7\stream_for($value); + $this->value = Utils::streamFor($value); } /** diff --git a/src/RequestBuilder.php b/src/RequestBuilder.php index fa6e957..0f31f93 100644 --- a/src/RequestBuilder.php +++ b/src/RequestBuilder.php @@ -17,7 +17,6 @@ namespace Google\Cloud\Core; -use GuzzleHttp\Psr7; use GuzzleHttp\Psr7\Request; use GuzzleHttp\Psr7\Uri; use Psr\Http\Message\RequestInterface; diff --git a/src/RequestWrapper.php b/src/RequestWrapper.php index e16f119..b699525 100644 --- a/src/RequestWrapper.php +++ b/src/RequestWrapper.php @@ -25,7 +25,7 @@ use Google\Cloud\Core\RequestWrapperTrait; use GuzzleHttp\Exception\RequestException; use GuzzleHttp\Promise\PromiseInterface; -use GuzzleHttp\Psr7; +use GuzzleHttp\Psr7\Utils; use Psr\Http\Message\RequestInterface; use Psr\Http\Message\ResponseInterface; use Psr\Http\Message\StreamInterface; @@ -304,7 +304,7 @@ private function applyHeaders(RequestInterface $request) } } - return Psr7\modify_request($request, ['set_headers' => $headers]); + return Utils::modifyRequest($request, ['set_headers' => $headers]); } /** diff --git a/src/Upload/AbstractUploader.php b/src/Upload/AbstractUploader.php index f3dccba..52a0587 100644 --- a/src/Upload/AbstractUploader.php +++ b/src/Upload/AbstractUploader.php @@ -19,7 +19,7 @@ use Google\Cloud\Core\RequestWrapper; use Google\Cloud\Core\UriTrait; -use GuzzleHttp\Psr7; +use GuzzleHttp\Psr7\Utils; use Psr\Http\Message\StreamInterface; /** @@ -96,7 +96,7 @@ public function __construct( array $options = [] ) { $this->requestWrapper = $requestWrapper; - $this->data = Psr7\stream_for($data); + $this->data = Utils::streamFor($data); $this->uri = $uri; $this->metadata = isset($options['metadata']) ? $options['metadata'] : []; $this->chunkSize = isset($options['chunkSize']) ? $options['chunkSize'] : null; diff --git a/src/Upload/ResumableUploader.php b/src/Upload/ResumableUploader.php index 40b8d7b..b47fbc2 100644 --- a/src/Upload/ResumableUploader.php +++ b/src/Upload/ResumableUploader.php @@ -23,7 +23,6 @@ use Google\Cloud\Core\JsonTrait; use Google\Cloud\Core\RequestWrapper; use GuzzleHttp\Promise\PromiseInterface; -use GuzzleHttp\Psr7; use GuzzleHttp\Psr7\LimitStream; use GuzzleHttp\Psr7\Request; use Psr\Http\Message\ResponseInterface; diff --git a/src/UriTrait.php b/src/UriTrait.php index 8b1df09..04237aa 100644 --- a/src/UriTrait.php +++ b/src/UriTrait.php @@ -17,7 +17,8 @@ namespace Google\Cloud\Core; -use GuzzleHttp\Psr7; +use GuzzleHttp\Psr7\Query; +use GuzzleHttp\Psr7\Utils; use Psr\Http\Message\UriInterface; use Rize\UriTemplate; @@ -59,6 +60,6 @@ public function buildUriWithQuery($uri, array $query) } } - return Psr7\uri_for($uri)->withQuery(Psr7\build_query($query)); + return Utils::uriFor($uri)->withQuery(Query::build($query)); } } diff --git a/tests/Unit/Upload/MultipartUploaderTest.php b/tests/Unit/Upload/MultipartUploaderTest.php index c01c8c5..e5e6add 100644 --- a/tests/Unit/Upload/MultipartUploaderTest.php +++ b/tests/Unit/Upload/MultipartUploaderTest.php @@ -20,14 +20,13 @@ use Google\Cloud\Core\RequestWrapper; use Google\Cloud\Core\Upload\MultipartUploader; use GuzzleHttp\Psr7; -use GuzzleHttp\Psr7\Request; use GuzzleHttp\Psr7\Response; use GuzzleHttp\Promise; use GuzzleHttp\Promise\PromiseInterface; +use GuzzleHttp\Psr7\Utils; use Prophecy\Argument; use Psr\Http\Message\RequestInterface; use PHPUnit\Framework\TestCase; -use Psr\Http\Message\StreamInterface; /** * @group core @@ -38,7 +37,7 @@ class MultipartUploaderTest extends TestCase public function testUploadsData() { $requestWrapper = $this->prophesize(RequestWrapper::class); - $stream = Psr7\stream_for('abcd'); + $stream = Utils::streamFor('abcd'); $successBody = '{"canI":"kickIt"}'; $response = new Response(200, [], $successBody); @@ -59,7 +58,7 @@ public function testUploadsData() public function testUploadsAsyncData() { $requestWrapper = $this->prophesize(RequestWrapper::class); - $stream = Psr7\stream_for('abcd'); + $stream = Utils::streamFor('abcd'); $successBody = '{"canI":"kickIt"}'; $response = new Response(200, [], $successBody); $promise = Promise\promise_for($response); diff --git a/tests/Unit/Upload/ResumableUploaderTest.php b/tests/Unit/Upload/ResumableUploaderTest.php index f66011e..29d0b45 100644 --- a/tests/Unit/Upload/ResumableUploaderTest.php +++ b/tests/Unit/Upload/ResumableUploaderTest.php @@ -20,9 +20,8 @@ use Google\Cloud\Core\Exception\GoogleException; use Google\Cloud\Core\RequestWrapper; use Google\Cloud\Core\Upload\ResumableUploader; -use GuzzleHttp\Psr7; -use GuzzleHttp\Psr7\Request; use GuzzleHttp\Psr7\Response; +use GuzzleHttp\Psr7\Utils; use Prophecy\Argument; use Psr\Http\Message\RequestInterface; use Psr\Http\Message\StreamInterface; @@ -41,7 +40,7 @@ class ResumableUploaderTest extends TestCase public function setUp() { $this->requestWrapper = $this->prophesize(RequestWrapper::class); - $this->stream = Psr7\stream_for('abcd'); + $this->stream = Utils::streamFor('abcd'); $this->successBody = '{"canI":"kickIt"}'; } diff --git a/tests/Unit/Upload/SignedUrlUploaderTest.php b/tests/Unit/Upload/SignedUrlUploaderTest.php index af42773..0f3c2be 100644 --- a/tests/Unit/Upload/SignedUrlUploaderTest.php +++ b/tests/Unit/Upload/SignedUrlUploaderTest.php @@ -20,12 +20,11 @@ use Google\Cloud\Core\Exception\GoogleException; use Google\Cloud\Core\RequestWrapper; use Google\Cloud\Core\Upload\SignedUrlUploader; -use GuzzleHttp\Psr7; use GuzzleHttp\Psr7\Request; use GuzzleHttp\Psr7\Response; +use GuzzleHttp\Psr7\Utils; use Prophecy\Argument; use Psr\Http\Message\RequestInterface; -use Psr\Http\Message\StreamInterface; use PHPUnit\Framework\TestCase; /** @@ -41,7 +40,7 @@ class SignedUrlUploaderTest extends TestCase public function setUp() { $this->requestWrapper = $this->prophesize(RequestWrapper::class); - $this->stream = Psr7\stream_for('abcd'); + $this->stream = Utils::streamFor('abcd'); $this->successBody = '{"canI":"kickIt"}'; }