From 4583284accc9670c2da226c94eec91de69f68d61 Mon Sep 17 00:00:00 2001 From: Constantin Ross Date: Sun, 11 Dec 2022 15:17:27 +0100 Subject: [PATCH 1/7] feat: update guzzle to version 7 --- composer.json | 2 +- composer.lock | 389 ++++++++---------- src/Prismic/Api.php | 2 +- .../Exception/RequestFailureException.php | 54 ++- tests/Prismic/ApiTest.php | 2 +- tests/Prismic/GuzzleClient.php | 20 - tests/Prismic/SearchFormTest.php | 3 +- 7 files changed, 217 insertions(+), 255 deletions(-) delete mode 100644 tests/Prismic/GuzzleClient.php diff --git a/composer.json b/composer.json index 4135e445..41de28a8 100644 --- a/composer.json +++ b/composer.json @@ -24,7 +24,7 @@ "ext-curl": "*", "ext-json": "*", "ext-mbstring": "*", - "guzzlehttp/guzzle": "^6.3" + "guzzlehttp/guzzle": "^6.3 || ^7.0" }, "require-dev": { "phpspec/prophecy": "^1.15", diff --git a/composer.lock b/composer.lock index 42a6152f..2b619f24 100644 --- a/composer.lock +++ b/composer.lock @@ -4,41 +4,53 @@ "Read more about it at https://getcomposer.org/doc/01-basic-usage.md#installing-dependencies", "This file is @generated automatically" ], - "content-hash": "d3be8e0db43ef593c339e57833437352", + "content-hash": "1319ccf8218448edb837e5bd1f24e235", "packages": [ { "name": "guzzlehttp/guzzle", - "version": "6.5.8", + "version": "7.5.0", "source": { "type": "git", "url": "https://github.com/guzzle/guzzle.git", - "reference": "a52f0440530b54fa079ce76e8c5d196a42cad981" + "reference": "b50a2a1251152e43f6a37f0fa053e730a67d25ba" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/guzzle/guzzle/zipball/a52f0440530b54fa079ce76e8c5d196a42cad981", - "reference": "a52f0440530b54fa079ce76e8c5d196a42cad981", + "url": "https://api.github.com/repos/guzzle/guzzle/zipball/b50a2a1251152e43f6a37f0fa053e730a67d25ba", + "reference": "b50a2a1251152e43f6a37f0fa053e730a67d25ba", "shasum": "" }, "require": { "ext-json": "*", - "guzzlehttp/promises": "^1.0", - "guzzlehttp/psr7": "^1.9", - "php": ">=5.5", - "symfony/polyfill-intl-idn": "^1.17" + "guzzlehttp/promises": "^1.5", + "guzzlehttp/psr7": "^1.9 || ^2.4", + "php": "^7.2.5 || ^8.0", + "psr/http-client": "^1.0", + "symfony/deprecation-contracts": "^2.2 || ^3.0" + }, + "provide": { + "psr/http-client-implementation": "1.0" }, "require-dev": { + "bamarni/composer-bin-plugin": "^1.8.1", "ext-curl": "*", - "phpunit/phpunit": "^4.8.35 || ^5.7 || ^6.4 || ^7.0", - "psr/log": "^1.1" + "php-http/client-integration-tests": "^3.0", + "phpunit/phpunit": "^8.5.29 || ^9.5.23", + "psr/log": "^1.1 || ^2.0 || ^3.0" }, "suggest": { + "ext-curl": "Required for CURL handler support", + "ext-intl": "Required for Internationalized Domain Name (IDN) support", "psr/log": "Required for using the Log middleware" }, "type": "library", "extra": { + "bamarni-bin": { + "bin-links": true, + "forward-command": false + }, "branch-alias": { - "dev-master": "6.5-dev" + "dev-master": "7.5-dev" } }, "autoload": { @@ -91,19 +103,20 @@ } ], "description": "Guzzle is a PHP HTTP client library", - "homepage": "http://guzzlephp.org/", "keywords": [ "client", "curl", "framework", "http", "http client", + "psr-18", + "psr-7", "rest", "web service" ], "support": { "issues": "https://github.com/guzzle/guzzle/issues", - "source": "https://github.com/guzzle/guzzle/tree/6.5.8" + "source": "https://github.com/guzzle/guzzle/tree/7.5.0" }, "funding": [ { @@ -119,7 +132,7 @@ "type": "tidelift" } ], - "time": "2022-06-20T22:16:07+00:00" + "time": "2022-08-28T15:39:27+00:00" }, { "name": "guzzlehttp/promises", @@ -207,43 +220,47 @@ }, { "name": "guzzlehttp/psr7", - "version": "1.9.0", + "version": "2.4.3", "source": { "type": "git", "url": "https://github.com/guzzle/psr7.git", - "reference": "e98e3e6d4f86621a9b75f623996e6bbdeb4b9318" + "reference": "67c26b443f348a51926030c83481b85718457d3d" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/guzzle/psr7/zipball/e98e3e6d4f86621a9b75f623996e6bbdeb4b9318", - "reference": "e98e3e6d4f86621a9b75f623996e6bbdeb4b9318", + "url": "https://api.github.com/repos/guzzle/psr7/zipball/67c26b443f348a51926030c83481b85718457d3d", + "reference": "67c26b443f348a51926030c83481b85718457d3d", "shasum": "" }, "require": { - "php": ">=5.4.0", - "psr/http-message": "~1.0", - "ralouphie/getallheaders": "^2.0.5 || ^3.0.0" + "php": "^7.2.5 || ^8.0", + "psr/http-factory": "^1.0", + "psr/http-message": "^1.0", + "ralouphie/getallheaders": "^3.0" }, "provide": { + "psr/http-factory-implementation": "1.0", "psr/http-message-implementation": "1.0" }, "require-dev": { - "ext-zlib": "*", - "phpunit/phpunit": "~4.8.36 || ^5.7.27 || ^6.5.14 || ^7.5.20 || ^8.5.8 || ^9.3.10" + "bamarni/composer-bin-plugin": "^1.8.1", + "http-interop/http-factory-tests": "^0.9", + "phpunit/phpunit": "^8.5.29 || ^9.5.23" }, "suggest": { "laminas/laminas-httphandlerrunner": "Emit PSR-7 responses" }, "type": "library", "extra": { + "bamarni-bin": { + "bin-links": true, + "forward-command": false + }, "branch-alias": { - "dev-master": "1.9-dev" + "dev-master": "2.4-dev" } }, "autoload": { - "files": [ - "src/functions_include.php" - ], "psr-4": { "GuzzleHttp\\Psr7\\": "src/" } @@ -282,6 +299,11 @@ "name": "Tobias Schultze", "email": "webmaster@tubo-world.de", "homepage": "https://github.com/Tobion" + }, + { + "name": "Márk Sági-Kazár", + "email": "mark.sagikazar@gmail.com", + "homepage": "https://sagikazarmark.hu" } ], "description": "PSR-7 message implementation that also provides common utility methods", @@ -297,7 +319,7 @@ ], "support": { "issues": "https://github.com/guzzle/psr7/issues", - "source": "https://github.com/guzzle/psr7/tree/1.9.0" + "source": "https://github.com/guzzle/psr7/tree/2.4.3" }, "funding": [ { @@ -313,24 +335,25 @@ "type": "tidelift" } ], - "time": "2022-06-20T21:43:03+00:00" + "time": "2022-10-26T14:07:24+00:00" }, { - "name": "psr/http-message", + "name": "psr/http-client", "version": "1.0.1", "source": { "type": "git", - "url": "https://github.com/php-fig/http-message.git", - "reference": "f6561bf28d520154e4b0ec72be95418abe6d9363" + "url": "https://github.com/php-fig/http-client.git", + "reference": "2dfb5f6c5eff0e91e20e913f8c5452ed95b86621" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/php-fig/http-message/zipball/f6561bf28d520154e4b0ec72be95418abe6d9363", - "reference": "f6561bf28d520154e4b0ec72be95418abe6d9363", + "url": "https://api.github.com/repos/php-fig/http-client/zipball/2dfb5f6c5eff0e91e20e913f8c5452ed95b86621", + "reference": "2dfb5f6c5eff0e91e20e913f8c5452ed95b86621", "shasum": "" }, "require": { - "php": ">=5.3.0" + "php": "^7.0 || ^8.0", + "psr/http-message": "^1.0" }, "type": "library", "extra": { @@ -340,7 +363,7 @@ }, "autoload": { "psr-4": { - "Psr\\Http\\Message\\": "src/" + "Psr\\Http\\Client\\": "src/" } }, "notification-url": "https://packagist.org/downloads/", @@ -353,47 +376,47 @@ "homepage": "http://www.php-fig.org/" } ], - "description": "Common interface for HTTP messages", - "homepage": "https://github.com/php-fig/http-message", + "description": "Common interface for HTTP clients", + "homepage": "https://github.com/php-fig/http-client", "keywords": [ "http", - "http-message", + "http-client", "psr", - "psr-7", - "request", - "response" + "psr-18" ], "support": { - "source": "https://github.com/php-fig/http-message/tree/master" + "source": "https://github.com/php-fig/http-client/tree/master" }, - "time": "2016-08-06T14:39:51+00:00" + "time": "2020-06-29T06:28:15+00:00" }, { - "name": "ralouphie/getallheaders", - "version": "3.0.3", + "name": "psr/http-factory", + "version": "1.0.1", "source": { "type": "git", - "url": "https://github.com/ralouphie/getallheaders.git", - "reference": "120b605dfeb996808c31b6477290a714d356e822" + "url": "https://github.com/php-fig/http-factory.git", + "reference": "12ac7fcd07e5b077433f5f2bee95b3a771bf61be" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/ralouphie/getallheaders/zipball/120b605dfeb996808c31b6477290a714d356e822", - "reference": "120b605dfeb996808c31b6477290a714d356e822", + "url": "https://api.github.com/repos/php-fig/http-factory/zipball/12ac7fcd07e5b077433f5f2bee95b3a771bf61be", + "reference": "12ac7fcd07e5b077433f5f2bee95b3a771bf61be", "shasum": "" }, "require": { - "php": ">=5.6" - }, - "require-dev": { - "php-coveralls/php-coveralls": "^2.1", - "phpunit/phpunit": "^5 || ^6.5" + "php": ">=7.0.0", + "psr/http-message": "^1.0" }, "type": "library", + "extra": { + "branch-alias": { + "dev-master": "1.0.x-dev" + } + }, "autoload": { - "files": [ - "src/getallheaders.php" - ] + "psr-4": { + "Psr\\Http\\Message\\": "src/" + } }, "notification-url": "https://packagist.org/downloads/", "license": [ @@ -401,55 +424,52 @@ ], "authors": [ { - "name": "Ralph Khattar", - "email": "ralph.khattar@gmail.com" + "name": "PHP-FIG", + "homepage": "http://www.php-fig.org/" } ], - "description": "A polyfill for getallheaders.", + "description": "Common interfaces for PSR-7 HTTP message factories", + "keywords": [ + "factory", + "http", + "message", + "psr", + "psr-17", + "psr-7", + "request", + "response" + ], "support": { - "issues": "https://github.com/ralouphie/getallheaders/issues", - "source": "https://github.com/ralouphie/getallheaders/tree/develop" + "source": "https://github.com/php-fig/http-factory/tree/master" }, - "time": "2019-03-08T08:55:37+00:00" + "time": "2019-04-30T12:38:16+00:00" }, { - "name": "symfony/polyfill-intl-idn", - "version": "v1.26.0", + "name": "psr/http-message", + "version": "1.0.1", "source": { "type": "git", - "url": "https://github.com/symfony/polyfill-intl-idn.git", - "reference": "59a8d271f00dd0e4c2e518104cc7963f655a1aa8" + "url": "https://github.com/php-fig/http-message.git", + "reference": "f6561bf28d520154e4b0ec72be95418abe6d9363" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/symfony/polyfill-intl-idn/zipball/59a8d271f00dd0e4c2e518104cc7963f655a1aa8", - "reference": "59a8d271f00dd0e4c2e518104cc7963f655a1aa8", + "url": "https://api.github.com/repos/php-fig/http-message/zipball/f6561bf28d520154e4b0ec72be95418abe6d9363", + "reference": "f6561bf28d520154e4b0ec72be95418abe6d9363", "shasum": "" }, "require": { - "php": ">=7.1", - "symfony/polyfill-intl-normalizer": "^1.10", - "symfony/polyfill-php72": "^1.10" - }, - "suggest": { - "ext-intl": "For best performance" + "php": ">=5.3.0" }, "type": "library", "extra": { "branch-alias": { - "dev-main": "1.26-dev" - }, - "thanks": { - "name": "symfony/polyfill", - "url": "https://github.com/symfony/polyfill" + "dev-master": "1.0.x-dev" } }, "autoload": { - "files": [ - "bootstrap.php" - ], "psr-4": { - "Symfony\\Polyfill\\Intl\\Idn\\": "" + "Psr\\Http\\Message\\": "src/" } }, "notification-url": "https://packagist.org/downloads/", @@ -458,86 +478,50 @@ ], "authors": [ { - "name": "Laurent Bassin", - "email": "laurent@bassin.info" - }, - { - "name": "Trevor Rowbotham", - "email": "trevor.rowbotham@pm.me" - }, - { - "name": "Symfony Community", - "homepage": "https://symfony.com/contributors" + "name": "PHP-FIG", + "homepage": "http://www.php-fig.org/" } ], - "description": "Symfony polyfill for intl's idn_to_ascii and idn_to_utf8 functions", - "homepage": "https://symfony.com", + "description": "Common interface for HTTP messages", + "homepage": "https://github.com/php-fig/http-message", "keywords": [ - "compatibility", - "idn", - "intl", - "polyfill", - "portable", - "shim" + "http", + "http-message", + "psr", + "psr-7", + "request", + "response" ], "support": { - "source": "https://github.com/symfony/polyfill-intl-idn/tree/v1.26.0" + "source": "https://github.com/php-fig/http-message/tree/master" }, - "funding": [ - { - "url": "https://symfony.com/sponsor", - "type": "custom" - }, - { - "url": "https://github.com/fabpot", - "type": "github" - }, - { - "url": "https://tidelift.com/funding/github/packagist/symfony/symfony", - "type": "tidelift" - } - ], - "time": "2022-05-24T11:49:31+00:00" + "time": "2016-08-06T14:39:51+00:00" }, { - "name": "symfony/polyfill-intl-normalizer", - "version": "v1.26.0", + "name": "ralouphie/getallheaders", + "version": "3.0.3", "source": { "type": "git", - "url": "https://github.com/symfony/polyfill-intl-normalizer.git", - "reference": "219aa369ceff116e673852dce47c3a41794c14bd" + "url": "https://github.com/ralouphie/getallheaders.git", + "reference": "120b605dfeb996808c31b6477290a714d356e822" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/symfony/polyfill-intl-normalizer/zipball/219aa369ceff116e673852dce47c3a41794c14bd", - "reference": "219aa369ceff116e673852dce47c3a41794c14bd", + "url": "https://api.github.com/repos/ralouphie/getallheaders/zipball/120b605dfeb996808c31b6477290a714d356e822", + "reference": "120b605dfeb996808c31b6477290a714d356e822", "shasum": "" }, "require": { - "php": ">=7.1" + "php": ">=5.6" }, - "suggest": { - "ext-intl": "For best performance" + "require-dev": { + "php-coveralls/php-coveralls": "^2.1", + "phpunit/phpunit": "^5 || ^6.5" }, "type": "library", - "extra": { - "branch-alias": { - "dev-main": "1.26-dev" - }, - "thanks": { - "name": "symfony/polyfill", - "url": "https://github.com/symfony/polyfill" - } - }, "autoload": { "files": [ - "bootstrap.php" - ], - "psr-4": { - "Symfony\\Polyfill\\Intl\\Normalizer\\": "" - }, - "classmap": [ - "Resources/stubs" + "src/getallheaders.php" ] }, "notification-url": "https://packagist.org/downloads/", @@ -546,55 +530,29 @@ ], "authors": [ { - "name": "Nicolas Grekas", - "email": "p@tchwork.com" - }, - { - "name": "Symfony Community", - "homepage": "https://symfony.com/contributors" + "name": "Ralph Khattar", + "email": "ralph.khattar@gmail.com" } ], - "description": "Symfony polyfill for intl's Normalizer class and related functions", - "homepage": "https://symfony.com", - "keywords": [ - "compatibility", - "intl", - "normalizer", - "polyfill", - "portable", - "shim" - ], + "description": "A polyfill for getallheaders.", "support": { - "source": "https://github.com/symfony/polyfill-intl-normalizer/tree/v1.26.0" + "issues": "https://github.com/ralouphie/getallheaders/issues", + "source": "https://github.com/ralouphie/getallheaders/tree/develop" }, - "funding": [ - { - "url": "https://symfony.com/sponsor", - "type": "custom" - }, - { - "url": "https://github.com/fabpot", - "type": "github" - }, - { - "url": "https://tidelift.com/funding/github/packagist/symfony/symfony", - "type": "tidelift" - } - ], - "time": "2022-05-24T11:49:31+00:00" + "time": "2019-03-08T08:55:37+00:00" }, { - "name": "symfony/polyfill-php72", - "version": "v1.26.0", + "name": "symfony/deprecation-contracts", + "version": "v2.5.2", "source": { "type": "git", - "url": "https://github.com/symfony/polyfill-php72.git", - "reference": "bf44a9fd41feaac72b074de600314a93e2ae78e2" + "url": "https://github.com/symfony/deprecation-contracts.git", + "reference": "e8b495ea28c1d97b5e0c121748d6f9b53d075c66" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/symfony/polyfill-php72/zipball/bf44a9fd41feaac72b074de600314a93e2ae78e2", - "reference": "bf44a9fd41feaac72b074de600314a93e2ae78e2", + "url": "https://api.github.com/repos/symfony/deprecation-contracts/zipball/e8b495ea28c1d97b5e0c121748d6f9b53d075c66", + "reference": "e8b495ea28c1d97b5e0c121748d6f9b53d075c66", "shasum": "" }, "require": { @@ -603,20 +561,17 @@ "type": "library", "extra": { "branch-alias": { - "dev-main": "1.26-dev" + "dev-main": "2.5-dev" }, "thanks": { - "name": "symfony/polyfill", - "url": "https://github.com/symfony/polyfill" + "name": "symfony/contracts", + "url": "https://github.com/symfony/contracts" } }, "autoload": { "files": [ - "bootstrap.php" - ], - "psr-4": { - "Symfony\\Polyfill\\Php72\\": "" - } + "function.php" + ] }, "notification-url": "https://packagist.org/downloads/", "license": [ @@ -632,16 +587,10 @@ "homepage": "https://symfony.com/contributors" } ], - "description": "Symfony polyfill backporting some PHP 7.2+ features to lower PHP versions", + "description": "A generic function and convention to trigger deprecation notices", "homepage": "https://symfony.com", - "keywords": [ - "compatibility", - "polyfill", - "portable", - "shim" - ], "support": { - "source": "https://github.com/symfony/polyfill-php72/tree/v1.26.0" + "source": "https://github.com/symfony/deprecation-contracts/tree/v2.5.2" }, "funding": [ { @@ -657,7 +606,7 @@ "type": "tidelift" } ], - "time": "2022-05-24T11:49:31+00:00" + "time": "2022-01-02T09:53:40+00:00" } ], "packages-dev": [ @@ -792,16 +741,16 @@ }, { "name": "nikic/php-parser", - "version": "v4.15.1", + "version": "v4.15.2", "source": { "type": "git", "url": "https://github.com/nikic/PHP-Parser.git", - "reference": "0ef6c55a3f47f89d7a374e6f835197a0b5fcf900" + "reference": "f59bbe44bf7d96f24f3e2b4ddc21cd52c1d2adbc" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/nikic/PHP-Parser/zipball/0ef6c55a3f47f89d7a374e6f835197a0b5fcf900", - "reference": "0ef6c55a3f47f89d7a374e6f835197a0b5fcf900", + "url": "https://api.github.com/repos/nikic/PHP-Parser/zipball/f59bbe44bf7d96f24f3e2b4ddc21cd52c1d2adbc", + "reference": "f59bbe44bf7d96f24f3e2b4ddc21cd52c1d2adbc", "shasum": "" }, "require": { @@ -842,9 +791,9 @@ ], "support": { "issues": "https://github.com/nikic/PHP-Parser/issues", - "source": "https://github.com/nikic/PHP-Parser/tree/v4.15.1" + "source": "https://github.com/nikic/PHP-Parser/tree/v4.15.2" }, - "time": "2022-09-04T07:30:47+00:00" + "time": "2022-11-12T15:38:23+00:00" }, { "name": "phar-io/manifest", @@ -1124,21 +1073,21 @@ }, { "name": "phpspec/prophecy", - "version": "v1.15.0", + "version": "v1.16.0", "source": { "type": "git", "url": "https://github.com/phpspec/prophecy.git", - "reference": "bbcd7380b0ebf3961ee21409db7b38bc31d69a13" + "reference": "be8cac52a0827776ff9ccda8c381ac5b71aeb359" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/phpspec/prophecy/zipball/bbcd7380b0ebf3961ee21409db7b38bc31d69a13", - "reference": "bbcd7380b0ebf3961ee21409db7b38bc31d69a13", + "url": "https://api.github.com/repos/phpspec/prophecy/zipball/be8cac52a0827776ff9ccda8c381ac5b71aeb359", + "reference": "be8cac52a0827776ff9ccda8c381ac5b71aeb359", "shasum": "" }, "require": { "doctrine/instantiator": "^1.2", - "php": "^7.2 || ~8.0, <8.2", + "php": "^7.2 || 8.0.* || 8.1.* || 8.2.*", "phpdocumentor/reflection-docblock": "^5.2", "sebastian/comparator": "^3.0 || ^4.0", "sebastian/recursion-context": "^3.0 || ^4.0" @@ -1185,9 +1134,9 @@ ], "support": { "issues": "https://github.com/phpspec/prophecy/issues", - "source": "https://github.com/phpspec/prophecy/tree/v1.15.0" + "source": "https://github.com/phpspec/prophecy/tree/v1.16.0" }, - "time": "2021-12-08T12:19:24+00:00" + "time": "2022-11-29T15:06:56+00:00" }, { "name": "phpspec/prophecy-phpunit", @@ -1243,16 +1192,16 @@ }, { "name": "phpunit/php-code-coverage", - "version": "9.2.18", + "version": "9.2.19", "source": { "type": "git", "url": "https://github.com/sebastianbergmann/php-code-coverage.git", - "reference": "12fddc491826940cf9b7e88ad9664cf51f0f6d0a" + "reference": "c77b56b63e3d2031bd8997fcec43c1925ae46559" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/sebastianbergmann/php-code-coverage/zipball/12fddc491826940cf9b7e88ad9664cf51f0f6d0a", - "reference": "12fddc491826940cf9b7e88ad9664cf51f0f6d0a", + "url": "https://api.github.com/repos/sebastianbergmann/php-code-coverage/zipball/c77b56b63e3d2031bd8997fcec43c1925ae46559", + "reference": "c77b56b63e3d2031bd8997fcec43c1925ae46559", "shasum": "" }, "require": { @@ -1308,7 +1257,7 @@ ], "support": { "issues": "https://github.com/sebastianbergmann/php-code-coverage/issues", - "source": "https://github.com/sebastianbergmann/php-code-coverage/tree/9.2.18" + "source": "https://github.com/sebastianbergmann/php-code-coverage/tree/9.2.19" }, "funding": [ { @@ -1316,7 +1265,7 @@ "type": "github" } ], - "time": "2022-10-27T13:35:33+00:00" + "time": "2022-11-18T07:47:47+00:00" }, { "name": "phpunit/php-file-iterator", @@ -2805,5 +2754,5 @@ "platform-overrides": { "php": "8.0" }, - "plugin-api-version": "2.2.0" + "plugin-api-version": "2.0.0" } diff --git a/src/Prismic/Api.php b/src/Prismic/Api.php index 9274e4d1..19987d12 100644 --- a/src/Prismic/Api.php +++ b/src/Prismic/Api.php @@ -318,7 +318,7 @@ public function submit() : array // Query the server for the rest if (count($promises) > 0) { - $raw_responses = Promise\unwrap($promises); + $raw_responses = Promise\Utils::unwrap($promises); foreach ($urls as $url) { $response = $raw_responses[$url]; diff --git a/src/Prismic/Exception/RequestFailureException.php b/src/Prismic/Exception/RequestFailureException.php index 0cd26d03..90912a90 100644 --- a/src/Prismic/Exception/RequestFailureException.php +++ b/src/Prismic/Exception/RequestFailureException.php @@ -1,12 +1,14 @@ guzzleException = $e; return $exception; } + /** - * Factory to wrap a Guzzle Request Exception when we should have access to a request and a response + * Factory to wrap a Guzzle Request or Connect Exception when we should have access + * to a request and a optionally response + * + * @param RequestException|ConnectException $e + * + * @return self */ - protected static function fromGuzzleRequestException(RequestException $e) : self + protected static function fromGuzzleRequestOrConnectException(GuzzleException $e): self { - $response = $e->getResponse(); + $response = $e instanceof RequestException ? $e->getResponse() : null; $code = $response ? $response->getStatusCode() : 0; $reason = $response ? $response->getReasonPhrase() : 'No Response'; $request = $e->getRequest(); @@ -54,19 +67,38 @@ protected static function fromGuzzleRequestException(RequestException $e) : self return $exception; } - public function getResponse() :? ResponseInterface + /** + * Returns the response that caused the exception, if available. + * Returns null if the exception does not have a response. + * + * Since Guzzle ^7.0 the ConnectException does not have a response, so null is returned. + * + * @return ResponseInterface|null + */ + public function getResponse(): ?ResponseInterface { - if (! $this->guzzleException instanceof RequestException) { + if (!$this->guzzleException instanceof RequestException) { return null; } + return $this->guzzleException->getResponse(); } - public function getRequest() :? RequestInterface + /** + * Returns the request that caused the exception, if available. + * Returns null if the exception does not have a request. + * + * @return RequestInterface|null + */ + public function getRequest(): ?RequestInterface { - if (! $this->guzzleException instanceof RequestException) { + if ( + !$this->guzzleException instanceof RequestException && + !$this->guzzleException instanceof ConnectException + ) { return null; } + return $this->guzzleException->getRequest(); } } diff --git a/tests/Prismic/ApiTest.php b/tests/Prismic/ApiTest.php index c43c7673..b8c9b281 100644 --- a/tests/Prismic/ApiTest.php +++ b/tests/Prismic/ApiTest.php @@ -40,7 +40,7 @@ public function setUp(): void unset($_COOKIE); $this->apiData = ApiData::withJsonString($this->getJsonFixture('data.json')); - $this->httpClient = $this->prophesize(GuzzleClient::class); + $this->httpClient = $this->prophesize(Client::class); $this->cache = $this->prophesize(CacheInterface::class); } diff --git a/tests/Prismic/GuzzleClient.php b/tests/Prismic/GuzzleClient.php deleted file mode 100644 index 0418d94c..00000000 --- a/tests/Prismic/GuzzleClient.php +++ /dev/null @@ -1,20 +0,0 @@ -apiData = ApiData::withJsonString($this->getJsonFixture('data.json')); $this->form = Form::withJsonObject($this->apiData->getForms()['blogs']); - $this->httpClient = $this->prophesize(GuzzleClient::class); + $this->httpClient = $this->prophesize(Client::class); $this->cache = $this->prophesize(CacheInterface::class); } From a4817e476e95705ce352c5f8f40df2bba73432f1 Mon Sep 17 00:00:00 2001 From: Constantin Ross Date: Sun, 11 Dec 2022 15:30:27 +0100 Subject: [PATCH 2/7] chore: cs fixes --- src/Prismic/Exception/RequestFailureException.php | 7 +++---- 1 file changed, 3 insertions(+), 4 deletions(-) diff --git a/src/Prismic/Exception/RequestFailureException.php b/src/Prismic/Exception/RequestFailureException.php index 90912a90..ee094b04 100644 --- a/src/Prismic/Exception/RequestFailureException.php +++ b/src/Prismic/Exception/RequestFailureException.php @@ -77,7 +77,7 @@ protected static function fromGuzzleRequestOrConnectException(GuzzleException $e */ public function getResponse(): ?ResponseInterface { - if (!$this->guzzleException instanceof RequestException) { + if (! $this->guzzleException instanceof RequestException) { return null; } @@ -92,9 +92,8 @@ public function getResponse(): ?ResponseInterface */ public function getRequest(): ?RequestInterface { - if ( - !$this->guzzleException instanceof RequestException && - !$this->guzzleException instanceof ConnectException + if (! $this->guzzleException instanceof RequestException && + ! $this->guzzleException instanceof ConnectException ) { return null; } From 93eaf2e1ba84a454ee736d5d70aa53dd56f23110 Mon Sep 17 00:00:00 2001 From: Constantin Ross Date: Tue, 13 Dec 2022 16:03:32 +0100 Subject: [PATCH 3/7] chore!: drop guzzle 6 for 7 --- composer.json | 2 +- composer.lock | 26 +++++++++++++------------- 2 files changed, 14 insertions(+), 14 deletions(-) diff --git a/composer.json b/composer.json index 41de28a8..42af796c 100644 --- a/composer.json +++ b/composer.json @@ -24,7 +24,7 @@ "ext-curl": "*", "ext-json": "*", "ext-mbstring": "*", - "guzzlehttp/guzzle": "^6.3 || ^7.0" + "guzzlehttp/guzzle": "^7.5" }, "require-dev": { "phpspec/prophecy": "^1.15", diff --git a/composer.lock b/composer.lock index 2b619f24..9b3fc716 100644 --- a/composer.lock +++ b/composer.lock @@ -4,7 +4,7 @@ "Read more about it at https://getcomposer.org/doc/01-basic-usage.md#installing-dependencies", "This file is @generated automatically" ], - "content-hash": "1319ccf8218448edb837e5bd1f24e235", + "content-hash": "41ababa821bc6669d4f620ff1d8efcea", "packages": [ { "name": "guzzlehttp/guzzle", @@ -1192,16 +1192,16 @@ }, { "name": "phpunit/php-code-coverage", - "version": "9.2.19", + "version": "9.2.20", "source": { "type": "git", "url": "https://github.com/sebastianbergmann/php-code-coverage.git", - "reference": "c77b56b63e3d2031bd8997fcec43c1925ae46559" + "reference": "af7463c955007de36db0c5e26d03e2f933c2e980" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/sebastianbergmann/php-code-coverage/zipball/c77b56b63e3d2031bd8997fcec43c1925ae46559", - "reference": "c77b56b63e3d2031bd8997fcec43c1925ae46559", + "url": "https://api.github.com/repos/sebastianbergmann/php-code-coverage/zipball/af7463c955007de36db0c5e26d03e2f933c2e980", + "reference": "af7463c955007de36db0c5e26d03e2f933c2e980", "shasum": "" }, "require": { @@ -1257,7 +1257,7 @@ ], "support": { "issues": "https://github.com/sebastianbergmann/php-code-coverage/issues", - "source": "https://github.com/sebastianbergmann/php-code-coverage/tree/9.2.19" + "source": "https://github.com/sebastianbergmann/php-code-coverage/tree/9.2.20" }, "funding": [ { @@ -1265,7 +1265,7 @@ "type": "github" } ], - "time": "2022-11-18T07:47:47+00:00" + "time": "2022-12-13T07:49:28+00:00" }, { "name": "phpunit/php-file-iterator", @@ -1510,16 +1510,16 @@ }, { "name": "phpunit/phpunit", - "version": "9.5.26", + "version": "9.5.27", "source": { "type": "git", "url": "https://github.com/sebastianbergmann/phpunit.git", - "reference": "851867efcbb6a1b992ec515c71cdcf20d895e9d2" + "reference": "a2bc7ffdca99f92d959b3f2270529334030bba38" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/sebastianbergmann/phpunit/zipball/851867efcbb6a1b992ec515c71cdcf20d895e9d2", - "reference": "851867efcbb6a1b992ec515c71cdcf20d895e9d2", + "url": "https://api.github.com/repos/sebastianbergmann/phpunit/zipball/a2bc7ffdca99f92d959b3f2270529334030bba38", + "reference": "a2bc7ffdca99f92d959b3f2270529334030bba38", "shasum": "" }, "require": { @@ -1592,7 +1592,7 @@ ], "support": { "issues": "https://github.com/sebastianbergmann/phpunit/issues", - "source": "https://github.com/sebastianbergmann/phpunit/tree/9.5.26" + "source": "https://github.com/sebastianbergmann/phpunit/tree/9.5.27" }, "funding": [ { @@ -1608,7 +1608,7 @@ "type": "tidelift" } ], - "time": "2022-10-28T06:00:21+00:00" + "time": "2022-12-09T07:31:23+00:00" }, { "name": "sebastian/cli-parser", From 132244bf4c513c7d35a20ea15b55d33e3a44d311 Mon Sep 17 00:00:00 2001 From: Constantin Ross Date: Wed, 4 Jan 2023 16:13:39 +0100 Subject: [PATCH 4/7] chore: switch to client interface --- tests/Prismic/ApiTest.php | 7 ++++--- tests/Prismic/SearchFormTest.php | 13 ++++++------- 2 files changed, 10 insertions(+), 10 deletions(-) mode change 100644 => 100755 tests/Prismic/ApiTest.php mode change 100644 => 100755 tests/Prismic/SearchFormTest.php diff --git a/tests/Prismic/ApiTest.php b/tests/Prismic/ApiTest.php old mode 100644 new mode 100755 index b8c9b281..b66de732 --- a/tests/Prismic/ApiTest.php +++ b/tests/Prismic/ApiTest.php @@ -1,4 +1,5 @@ apiData = ApiData::withJsonString($this->getJsonFixture('data.json')); - $this->httpClient = $this->prophesize(Client::class); + $this->httpClient = $this->prophesize(ClientInterface::class); $this->cache = $this->prophesize(CacheInterface::class); } - protected function getApi() : Api + protected function getApi(): Api { return Api::get( 'https://whatever.prismic.io/api/v2', @@ -55,7 +56,7 @@ protected function getApi() : Api ); } - protected function getApiWithDefaultData() : Api + protected function getApiWithDefaultData(): Api { $key = 'https://whatever.prismic.io/api/v2#My-Access-Token'; $cachedData = serialize($this->apiData); diff --git a/tests/Prismic/SearchFormTest.php b/tests/Prismic/SearchFormTest.php old mode 100644 new mode 100755 index 3852c823..64a848bb --- a/tests/Prismic/SearchFormTest.php +++ b/tests/Prismic/SearchFormTest.php @@ -1,11 +1,10 @@ apiData = ApiData::withJsonString($this->getJsonFixture('data.json')); $this->form = Form::withJsonObject($this->apiData->getForms()['blogs']); - $this->httpClient = $this->prophesize(Client::class); + $this->httpClient = $this->prophesize(ClientInterface::class); $this->cache = $this->prophesize(CacheInterface::class); } - protected function getSearchForm() : SearchForm + protected function getSearchForm(): SearchForm { return new SearchForm( $this->httpClient->reveal(), @@ -216,7 +215,7 @@ public function testFetchWithStringArgs() public function testFetchWithArrayArg() { $this->assertScalarOptionIsSet( - $this->getSearchForm()->fetch(...['one','two','three']), + $this->getSearchForm()->fetch(...['one', 'two', 'three']), 'fetch', 'one,two,three' ); @@ -402,7 +401,7 @@ public function testGuzzleExceptionsAreWrappedInSubmit() } } - private function prepareResponse(?string $body = null) : Response + private function prepareResponse(?string $body = null): Response { $body = $body ? $body : '{"data":"data"}'; $response = new Response( From 4be490c93e736764dbe49c7b685b46c7b72b43de Mon Sep 17 00:00:00 2001 From: Constantin Ross Date: Wed, 4 Jan 2023 16:14:14 +0100 Subject: [PATCH 5/7] refactor: deprecate old exception function --- .../Exception/RequestFailureException.php | 31 ++++++++++++++++--- 1 file changed, 26 insertions(+), 5 deletions(-) mode change 100644 => 100755 src/Prismic/Exception/RequestFailureException.php diff --git a/src/Prismic/Exception/RequestFailureException.php b/src/Prismic/Exception/RequestFailureException.php old mode 100644 new mode 100755 index ee094b04..b732d341 --- a/src/Prismic/Exception/RequestFailureException.php +++ b/src/Prismic/Exception/RequestFailureException.php @@ -27,7 +27,11 @@ class RequestFailureException extends RuntimeException */ public static function fromGuzzleException(GuzzleException $e): self { - if ($e instanceof RequestException || $e instanceof ConnectException) { + if ($e instanceof RequestException) { + return static::fromGuzzleRequestException($e); + } + + if ($e instanceof ConnectException) { return static::fromGuzzleRequestOrConnectException($e); } @@ -37,6 +41,22 @@ public static function fromGuzzleException(GuzzleException $e): self } + /** + * Factory to wrap a Guzzle Request Exception when we should have access to a request and a response. + * + * This function is deprectaed and will be removed in a future release. + * + * @deprecated since v5.3.0 + * + * @param RequestException $e + * + * @return self + */ + protected static function fromGuzzleRequestException(RequestException $e): self + { + return static::fromGuzzleRequestOrConnectException($e); + } + /** * Factory to wrap a Guzzle Request or Connect Exception when we should have access * to a request and a optionally response @@ -45,7 +65,7 @@ public static function fromGuzzleException(GuzzleException $e): self * * @return self */ - protected static function fromGuzzleRequestOrConnectException(GuzzleException $e): self + private static function fromGuzzleRequestOrConnectException(GuzzleException $e): self { $response = $e instanceof RequestException ? $e->getResponse() : null; $code = $response ? $response->getStatusCode() : 0; @@ -77,7 +97,7 @@ protected static function fromGuzzleRequestOrConnectException(GuzzleException $e */ public function getResponse(): ?ResponseInterface { - if (! $this->guzzleException instanceof RequestException) { + if (!$this->guzzleException instanceof RequestException) { return null; } @@ -92,8 +112,9 @@ public function getResponse(): ?ResponseInterface */ public function getRequest(): ?RequestInterface { - if (! $this->guzzleException instanceof RequestException && - ! $this->guzzleException instanceof ConnectException + if ( + !$this->guzzleException instanceof RequestException && + !$this->guzzleException instanceof ConnectException ) { return null; } From 2873800bd71cb89f29bf85d32525dd5775a4c17a Mon Sep 17 00:00:00 2001 From: Constantin Ross Date: Wed, 4 Jan 2023 16:16:54 +0100 Subject: [PATCH 6/7] chore: cs fixes --- src/Prismic/Exception/RequestFailureException.php | 7 +++---- 1 file changed, 3 insertions(+), 4 deletions(-) diff --git a/src/Prismic/Exception/RequestFailureException.php b/src/Prismic/Exception/RequestFailureException.php index b732d341..6918915c 100755 --- a/src/Prismic/Exception/RequestFailureException.php +++ b/src/Prismic/Exception/RequestFailureException.php @@ -97,7 +97,7 @@ private static function fromGuzzleRequestOrConnectException(GuzzleException $e): */ public function getResponse(): ?ResponseInterface { - if (!$this->guzzleException instanceof RequestException) { + if (! $this->guzzleException instanceof RequestException) { return null; } @@ -112,9 +112,8 @@ public function getResponse(): ?ResponseInterface */ public function getRequest(): ?RequestInterface { - if ( - !$this->guzzleException instanceof RequestException && - !$this->guzzleException instanceof ConnectException + if (! $this->guzzleException instanceof RequestException && + ! $this->guzzleException instanceof ConnectException ) { return null; } From 64b7beb6c6fde47ef1dfcd9fa9c05c9e19dc2082 Mon Sep 17 00:00:00 2001 From: Constantin Ross Date: Thu, 5 Jan 2023 10:08:36 +0100 Subject: [PATCH 7/7] docs: mark request failure exception as final Co-authored-by: George Steel --- src/Prismic/Exception/RequestFailureException.php | 1 + 1 file changed, 1 insertion(+) diff --git a/src/Prismic/Exception/RequestFailureException.php b/src/Prismic/Exception/RequestFailureException.php index 6918915c..123dc98a 100755 --- a/src/Prismic/Exception/RequestFailureException.php +++ b/src/Prismic/Exception/RequestFailureException.php @@ -10,6 +10,7 @@ use Psr\Http\Message\RequestInterface; use Psr\Http\Message\ResponseInterface; +/** @final This class is not designed to be open to extension */ class RequestFailureException extends RuntimeException {