diff --git a/.gitignore b/.gitignore index 89aaa15..4668293 100644 --- a/.gitignore +++ b/.gitignore @@ -6,3 +6,6 @@ phpspec.yml phpunit.xml .php_cs.cache .php-cs-fixer.cache + +### PhpStorm ### +.idea diff --git a/composer.lock b/composer.lock index 987b684..c9cbbde 100644 --- a/composer.lock +++ b/composer.lock @@ -8,16 +8,16 @@ "packages": [ { "name": "php-http/discovery", - "version": "1.15.2", + "version": "1.19.0", "source": { "type": "git", "url": "https://github.com/php-http/discovery.git", - "reference": "5cc428320191ac1d0b6520034c2dc0698628ced5" + "reference": "1856a119a0b0ba8da8b5c33c080aa7af8fac25b4" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/php-http/discovery/zipball/5cc428320191ac1d0b6520034c2dc0698628ced5", - "reference": "5cc428320191ac1d0b6520034c2dc0698628ced5", + "url": "https://api.github.com/repos/php-http/discovery/zipball/1856a119a0b0ba8da8b5c33c080aa7af8fac25b4", + "reference": "1856a119a0b0ba8da8b5c33c080aa7af8fac25b4", "shasum": "" }, "require": { @@ -25,7 +25,8 @@ "php": "^7.1 || ^8.0" }, "conflict": { - "nyholm/psr7": "<1.0" + "nyholm/psr7": "<1.0", + "zendframework/zend-diactoros": "*" }, "provide": { "php-http/async-client-implementation": "*", @@ -50,7 +51,10 @@ "autoload": { "psr-4": { "Http\\Discovery\\": "src/" - } + }, + "exclude-from-classmap": [ + "src/Composer/Plugin.php" + ] }, "notification-url": "https://packagist.org/downloads/", "license": [ @@ -76,40 +80,35 @@ ], "support": { "issues": "https://github.com/php-http/discovery/issues", - "source": "https://github.com/php-http/discovery/tree/1.15.2" + "source": "https://github.com/php-http/discovery/tree/1.19.0" }, - "time": "2023-02-11T08:28:41+00:00" + "time": "2023-06-19T08:45:36+00:00" }, { "name": "php-http/httplug", - "version": "2.3.0", + "version": "2.4.0", "source": { "type": "git", "url": "https://github.com/php-http/httplug.git", - "reference": "f640739f80dfa1152533976e3c112477f69274eb" + "reference": "625ad742c360c8ac580fcc647a1541d29e257f67" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/php-http/httplug/zipball/f640739f80dfa1152533976e3c112477f69274eb", - "reference": "f640739f80dfa1152533976e3c112477f69274eb", + "url": "https://api.github.com/repos/php-http/httplug/zipball/625ad742c360c8ac580fcc647a1541d29e257f67", + "reference": "625ad742c360c8ac580fcc647a1541d29e257f67", "shasum": "" }, "require": { "php": "^7.1 || ^8.0", "php-http/promise": "^1.1", "psr/http-client": "^1.0", - "psr/http-message": "^1.0" + "psr/http-message": "^1.0 || ^2.0" }, "require-dev": { - "friends-of-phpspec/phpspec-code-coverage": "^4.1", - "phpspec/phpspec": "^5.1 || ^6.0" + "friends-of-phpspec/phpspec-code-coverage": "^4.1 || ^5.0 || ^6.0", + "phpspec/phpspec": "^5.1 || ^6.0 || ^7.0" }, "type": "library", - "extra": { - "branch-alias": { - "dev-master": "2.x-dev" - } - }, "autoload": { "psr-4": { "Http\\Client\\": "src/" @@ -138,96 +137,36 @@ ], "support": { "issues": "https://github.com/php-http/httplug/issues", - "source": "https://github.com/php-http/httplug/tree/2.3.0" + "source": "https://github.com/php-http/httplug/tree/2.4.0" }, - "time": "2022-02-21T09:52:22+00:00" - }, - { - "name": "php-http/message-factory", - "version": "v1.0.2", - "source": { - "type": "git", - "url": "https://github.com/php-http/message-factory.git", - "reference": "a478cb11f66a6ac48d8954216cfed9aa06a501a1" - }, - "dist": { - "type": "zip", - "url": "https://api.github.com/repos/php-http/message-factory/zipball/a478cb11f66a6ac48d8954216cfed9aa06a501a1", - "reference": "a478cb11f66a6ac48d8954216cfed9aa06a501a1", - "shasum": "" - }, - "require": { - "php": ">=5.4", - "psr/http-message": "^1.0" - }, - "type": "library", - "extra": { - "branch-alias": { - "dev-master": "1.0-dev" - } - }, - "autoload": { - "psr-4": { - "Http\\Message\\": "src/" - } - }, - "notification-url": "https://packagist.org/downloads/", - "license": [ - "MIT" - ], - "authors": [ - { - "name": "Márk Sági-Kazár", - "email": "mark.sagikazar@gmail.com" - } - ], - "description": "Factory interfaces for PSR-7 HTTP Message", - "homepage": "http://php-http.org", - "keywords": [ - "factory", - "http", - "message", - "stream", - "uri" - ], - "support": { - "issues": "https://github.com/php-http/message-factory/issues", - "source": "https://github.com/php-http/message-factory/tree/master" - }, - "time": "2015-12-19T14:08:53+00:00" + "time": "2023-04-14T15:10:03+00:00" }, { "name": "php-http/multipart-stream-builder", - "version": "1.2.0", + "version": "1.3.0", "source": { "type": "git", "url": "https://github.com/php-http/multipart-stream-builder.git", - "reference": "11c1d31f72e01c738bbce9e27649a7cca829c30e" + "reference": "f5938fd135d9fa442cc297dc98481805acfe2b6a" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/php-http/multipart-stream-builder/zipball/11c1d31f72e01c738bbce9e27649a7cca829c30e", - "reference": "11c1d31f72e01c738bbce9e27649a7cca829c30e", + "url": "https://api.github.com/repos/php-http/multipart-stream-builder/zipball/f5938fd135d9fa442cc297dc98481805acfe2b6a", + "reference": "f5938fd135d9fa442cc297dc98481805acfe2b6a", "shasum": "" }, "require": { "php": "^7.1 || ^8.0", - "php-http/discovery": "^1.7", - "php-http/message-factory": "^1.0.2", - "psr/http-factory": "^1.0", - "psr/http-message": "^1.0" + "php-http/discovery": "^1.15", + "psr/http-factory-implementation": "^1.0" }, "require-dev": { "nyholm/psr7": "^1.0", "php-http/message": "^1.5", + "php-http/message-factory": "^1.0.2", "phpunit/phpunit": "^7.5.15 || ^8.5 || ^9.3" }, "type": "library", - "extra": { - "branch-alias": { - "dev-master": "1.x-dev" - } - }, "autoload": { "psr-4": { "Http\\Message\\MultipartStream\\": "src/" @@ -254,9 +193,9 @@ ], "support": { "issues": "https://github.com/php-http/multipart-stream-builder/issues", - "source": "https://github.com/php-http/multipart-stream-builder/tree/1.2.0" + "source": "https://github.com/php-http/multipart-stream-builder/tree/1.3.0" }, - "time": "2021-05-21T08:32:01+00:00" + "time": "2023-04-28T14:10:22+00:00" }, { "name": "php-http/promise", @@ -317,21 +256,21 @@ }, { "name": "psr/http-client", - "version": "1.0.1", + "version": "1.0.2", "source": { "type": "git", "url": "https://github.com/php-fig/http-client.git", - "reference": "2dfb5f6c5eff0e91e20e913f8c5452ed95b86621" + "reference": "0955afe48220520692d2d09f7ab7e0f93ffd6a31" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/php-fig/http-client/zipball/2dfb5f6c5eff0e91e20e913f8c5452ed95b86621", - "reference": "2dfb5f6c5eff0e91e20e913f8c5452ed95b86621", + "url": "https://api.github.com/repos/php-fig/http-client/zipball/0955afe48220520692d2d09f7ab7e0f93ffd6a31", + "reference": "0955afe48220520692d2d09f7ab7e0f93ffd6a31", "shasum": "" }, "require": { "php": "^7.0 || ^8.0", - "psr/http-message": "^1.0" + "psr/http-message": "^1.0 || ^2.0" }, "type": "library", "extra": { @@ -351,7 +290,7 @@ "authors": [ { "name": "PHP-FIG", - "homepage": "http://www.php-fig.org/" + "homepage": "https://www.php-fig.org/" } ], "description": "Common interface for HTTP clients", @@ -363,9 +302,9 @@ "psr-18" ], "support": { - "source": "https://github.com/php-fig/http-client/tree/master" + "source": "https://github.com/php-fig/http-client/tree/1.0.2" }, - "time": "2020-06-29T06:28:15+00:00" + "time": "2023-04-10T20:12:12+00:00" }, { "name": "psr/http-factory", @@ -544,16 +483,16 @@ }, { "name": "symfony/options-resolver", - "version": "v5.4.19", + "version": "v5.4.21", "source": { "type": "git", "url": "https://github.com/symfony/options-resolver.git", - "reference": "b03c99236445492f20c61666e8f7e5d388b078e5" + "reference": "4fe5cf6ede71096839f0e4b4444d65dd3a7c1eb9" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/symfony/options-resolver/zipball/b03c99236445492f20c61666e8f7e5d388b078e5", - "reference": "b03c99236445492f20c61666e8f7e5d388b078e5", + "url": "https://api.github.com/repos/symfony/options-resolver/zipball/4fe5cf6ede71096839f0e4b4444d65dd3a7c1eb9", + "reference": "4fe5cf6ede71096839f0e4b4444d65dd3a7c1eb9", "shasum": "" }, "require": { @@ -593,7 +532,7 @@ "options" ], "support": { - "source": "https://github.com/symfony/options-resolver/tree/v5.4.19" + "source": "https://github.com/symfony/options-resolver/tree/v5.4.21" }, "funding": [ { @@ -609,7 +548,7 @@ "type": "tidelift" } ], - "time": "2023-01-01T08:32:19+00:00" + "time": "2023-02-14T08:03:56+00:00" }, { "name": "symfony/polyfill-php73", @@ -1071,25 +1010,29 @@ }, { "name": "doctrine/deprecations", - "version": "v1.0.0", + "version": "v1.1.1", "source": { "type": "git", "url": "https://github.com/doctrine/deprecations.git", - "reference": "0e2a4f1f8cdfc7a92ec3b01c9334898c806b30de" + "reference": "612a3ee5ab0d5dd97b7cf3874a6efe24325efac3" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/doctrine/deprecations/zipball/0e2a4f1f8cdfc7a92ec3b01c9334898c806b30de", - "reference": "0e2a4f1f8cdfc7a92ec3b01c9334898c806b30de", + "url": "https://api.github.com/repos/doctrine/deprecations/zipball/612a3ee5ab0d5dd97b7cf3874a6efe24325efac3", + "reference": "612a3ee5ab0d5dd97b7cf3874a6efe24325efac3", "shasum": "" }, "require": { - "php": "^7.1|^8.0" + "php": "^7.1 || ^8.0" }, "require-dev": { "doctrine/coding-standard": "^9", - "phpunit/phpunit": "^7.5|^8.5|^9.5", - "psr/log": "^1|^2|^3" + "phpstan/phpstan": "1.4.10 || 1.10.15", + "phpstan/phpstan-phpunit": "^1.0", + "phpunit/phpunit": "^7.5 || ^8.5 || ^9.5", + "psalm/plugin-phpunit": "0.18.4", + "psr/log": "^1 || ^2 || ^3", + "vimeo/psalm": "4.30.0 || 5.12.0" }, "suggest": { "psr/log": "Allows logging deprecations via PSR-3 logger implementation" @@ -1108,9 +1051,9 @@ "homepage": "https://www.doctrine-project.org/", "support": { "issues": "https://github.com/doctrine/deprecations/issues", - "source": "https://github.com/doctrine/deprecations/tree/v1.0.0" + "source": "https://github.com/doctrine/deprecations/tree/v1.1.1" }, - "time": "2022-05-02T15:47:09+00:00" + "time": "2023-06-03T09:27:29+00:00" }, { "name": "doctrine/instantiator", @@ -1529,16 +1472,16 @@ }, { "name": "guzzlehttp/promises", - "version": "1.5.2", + "version": "1.5.3", "source": { "type": "git", "url": "https://github.com/guzzle/promises.git", - "reference": "b94b2807d85443f9719887892882d0329d1e2598" + "reference": "67ab6e18aaa14d753cc148911d273f6e6cb6721e" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/guzzle/promises/zipball/b94b2807d85443f9719887892882d0329d1e2598", - "reference": "b94b2807d85443f9719887892882d0329d1e2598", + "url": "https://api.github.com/repos/guzzle/promises/zipball/67ab6e18aaa14d753cc148911d273f6e6cb6721e", + "reference": "67ab6e18aaa14d753cc148911d273f6e6cb6721e", "shasum": "" }, "require": { @@ -1548,11 +1491,6 @@ "symfony/phpunit-bridge": "^4.4 || ^5.1" }, "type": "library", - "extra": { - "branch-alias": { - "dev-master": "1.5-dev" - } - }, "autoload": { "files": [ "src/functions_include.php" @@ -1593,7 +1531,7 @@ ], "support": { "issues": "https://github.com/guzzle/promises/issues", - "source": "https://github.com/guzzle/promises/tree/1.5.2" + "source": "https://github.com/guzzle/promises/tree/1.5.3" }, "funding": [ { @@ -1609,7 +1547,7 @@ "type": "tidelift" } ], - "time": "2022-08-28T14:55:35+00:00" + "time": "2023-05-21T12:31:43+00:00" }, { "name": "guzzlehttp/psr7", @@ -1776,16 +1714,16 @@ }, { "name": "myclabs/deep-copy", - "version": "1.11.0", + "version": "1.11.1", "source": { "type": "git", "url": "https://github.com/myclabs/DeepCopy.git", - "reference": "14daed4296fae74d9e3201d2c4925d1acb7aa614" + "reference": "7284c22080590fb39f2ffa3e9057f10a4ddd0e0c" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/myclabs/DeepCopy/zipball/14daed4296fae74d9e3201d2c4925d1acb7aa614", - "reference": "14daed4296fae74d9e3201d2c4925d1acb7aa614", + "url": "https://api.github.com/repos/myclabs/DeepCopy/zipball/7284c22080590fb39f2ffa3e9057f10a4ddd0e0c", + "reference": "7284c22080590fb39f2ffa3e9057f10a4ddd0e0c", "shasum": "" }, "require": { @@ -1823,7 +1761,7 @@ ], "support": { "issues": "https://github.com/myclabs/DeepCopy/issues", - "source": "https://github.com/myclabs/DeepCopy/tree/1.11.0" + "source": "https://github.com/myclabs/DeepCopy/tree/1.11.1" }, "funding": [ { @@ -1831,7 +1769,7 @@ "type": "tidelift" } ], - "time": "2022-03-03T13:19:32+00:00" + "time": "2023-03-08T13:26:56+00:00" }, { "name": "phar-io/manifest", @@ -2176,24 +2114,27 @@ }, { "name": "phpdocumentor/type-resolver", - "version": "1.6.2", + "version": "1.7.2", "source": { "type": "git", "url": "https://github.com/phpDocumentor/TypeResolver.git", - "reference": "48f445a408c131e38cab1c235aa6d2bb7a0bb20d" + "reference": "b2fe4d22a5426f38e014855322200b97b5362c0d" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/phpDocumentor/TypeResolver/zipball/48f445a408c131e38cab1c235aa6d2bb7a0bb20d", - "reference": "48f445a408c131e38cab1c235aa6d2bb7a0bb20d", + "url": "https://api.github.com/repos/phpDocumentor/TypeResolver/zipball/b2fe4d22a5426f38e014855322200b97b5362c0d", + "reference": "b2fe4d22a5426f38e014855322200b97b5362c0d", "shasum": "" }, "require": { + "doctrine/deprecations": "^1.0", "php": "^7.4 || ^8.0", - "phpdocumentor/reflection-common": "^2.0" + "phpdocumentor/reflection-common": "^2.0", + "phpstan/phpdoc-parser": "^1.13" }, "require-dev": { "ext-tokenizer": "*", + "phpbench/phpbench": "^1.2", "phpstan/extension-installer": "^1.1", "phpstan/phpstan": "^1.8", "phpstan/phpstan-phpunit": "^1.1", @@ -2225,9 +2166,9 @@ "description": "A PSR-5 based resolver of Class names, Types and Structural Element Names", "support": { "issues": "https://github.com/phpDocumentor/TypeResolver/issues", - "source": "https://github.com/phpDocumentor/TypeResolver/tree/1.6.2" + "source": "https://github.com/phpDocumentor/TypeResolver/tree/1.7.2" }, - "time": "2022-10-14T12:47:21+00:00" + "time": "2023-05-30T18:13:47+00:00" }, { "name": "phpspec/php-diff", @@ -2272,25 +2213,25 @@ }, { "name": "phpspec/phpspec", - "version": "7.3.0", + "version": "7.4.0", "source": { "type": "git", "url": "https://github.com/phpspec/phpspec.git", - "reference": "7e44b188e8e01f9c9a8ca6cb0d7aceaabcea2133" + "reference": "28faa87d1151a15848166226f33de61cb7107d0d" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/phpspec/phpspec/zipball/7e44b188e8e01f9c9a8ca6cb0d7aceaabcea2133", - "reference": "7e44b188e8e01f9c9a8ca6cb0d7aceaabcea2133", + "url": "https://api.github.com/repos/phpspec/phpspec/zipball/28faa87d1151a15848166226f33de61cb7107d0d", + "reference": "28faa87d1151a15848166226f33de61cb7107d0d", "shasum": "" }, "require": { - "doctrine/instantiator": "^1.0.5", + "doctrine/instantiator": "^1.0.5 || ^2", "ext-tokenizer": "*", "php": "^7.3 || 8.0.* || 8.1.* || 8.2.*", "phpspec/php-diff": "^1.0.0", "phpspec/prophecy": "^1.9", - "sebastian/exporter": "^3.0 || ^4.0", + "sebastian/exporter": "^3.0 || ^4.0 || ^5.0", "symfony/console": "^3.4 || ^4.4 || ^5.0 || ^6.0", "symfony/event-dispatcher": "^3.4 || ^4.4 || ^5.0 || ^6.0", "symfony/finder": "^3.4 || ^4.4 || ^5.0 || ^6.0", @@ -2302,9 +2243,9 @@ }, "require-dev": { "behat/behat": "^3.3", - "phpunit/phpunit": "^8.0 || ^9.0", + "phpunit/phpunit": "^8.0 || ^9.0 || ^10.0", "symfony/filesystem": "^3.4 || ^4.0 || ^5.0 || ^6.0", - "vimeo/psalm": "^4.3" + "vimeo/psalm": "^4.3 || ^5.2" }, "suggest": { "phpspec/nyan-formatters": "Adds Nyan formatters" @@ -2315,7 +2256,7 @@ "type": "library", "extra": { "branch-alias": { - "dev-main": "7.3.x-dev" + "dev-main": "7.4.x-dev" } }, "autoload": { @@ -2355,9 +2296,9 @@ ], "support": { "issues": "https://github.com/phpspec/phpspec/issues", - "source": "https://github.com/phpspec/phpspec/tree/7.3.0" + "source": "https://github.com/phpspec/phpspec/tree/7.4.0" }, - "time": "2022-12-14T16:15:59+00:00" + "time": "2023-04-21T13:17:48+00:00" }, { "name": "phpspec/prophecy", @@ -2427,18 +2368,65 @@ }, "time": "2023-02-02T15:41:36+00:00" }, + { + "name": "phpstan/phpdoc-parser", + "version": "1.22.0", + "source": { + "type": "git", + "url": "https://github.com/phpstan/phpdoc-parser.git", + "reference": "ec58baf7b3c7f1c81b3b00617c953249fb8cf30c" + }, + "dist": { + "type": "zip", + "url": "https://api.github.com/repos/phpstan/phpdoc-parser/zipball/ec58baf7b3c7f1c81b3b00617c953249fb8cf30c", + "reference": "ec58baf7b3c7f1c81b3b00617c953249fb8cf30c", + "shasum": "" + }, + "require": { + "php": "^7.2 || ^8.0" + }, + "require-dev": { + "doctrine/annotations": "^2.0", + "nikic/php-parser": "^4.15", + "php-parallel-lint/php-parallel-lint": "^1.2", + "phpstan/extension-installer": "^1.0", + "phpstan/phpstan": "^1.5", + "phpstan/phpstan-phpunit": "^1.1", + "phpstan/phpstan-strict-rules": "^1.0", + "phpunit/phpunit": "^9.5", + "symfony/process": "^5.2" + }, + "type": "library", + "autoload": { + "psr-4": { + "PHPStan\\PhpDocParser\\": [ + "src/" + ] + } + }, + "notification-url": "https://packagist.org/downloads/", + "license": [ + "MIT" + ], + "description": "PHPDoc parser with support for nullable, intersection and generic types", + "support": { + "issues": "https://github.com/phpstan/phpdoc-parser/issues", + "source": "https://github.com/phpstan/phpdoc-parser/tree/1.22.0" + }, + "time": "2023-06-01T12:35:21+00:00" + }, { "name": "phpstan/phpstan", - "version": "1.10.2", + "version": "1.10.21", "source": { "type": "git", "url": "https://github.com/phpstan/phpstan.git", - "reference": "a2ffec7db373d8da4973d1d62add872db5cd22dd" + "reference": "b2a30186be2e4d97dce754ae4e65eb0ec2f04eb5" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/phpstan/phpstan/zipball/a2ffec7db373d8da4973d1d62add872db5cd22dd", - "reference": "a2ffec7db373d8da4973d1d62add872db5cd22dd", + "url": "https://api.github.com/repos/phpstan/phpstan/zipball/b2a30186be2e4d97dce754ae4e65eb0ec2f04eb5", + "reference": "b2a30186be2e4d97dce754ae4e65eb0ec2f04eb5", "shasum": "" }, "require": { @@ -2467,8 +2455,11 @@ "static analysis" ], "support": { + "docs": "https://phpstan.org/user-guide/getting-started", + "forum": "https://github.com/phpstan/phpstan/discussions", "issues": "https://github.com/phpstan/phpstan/issues", - "source": "https://github.com/phpstan/phpstan/tree/1.10.2" + "security": "https://github.com/phpstan/phpstan/security/policy", + "source": "https://github.com/phpstan/phpstan-src" }, "funding": [ { @@ -2484,7 +2475,7 @@ "type": "tidelift" } ], - "time": "2023-02-23T14:36:46+00:00" + "time": "2023-06-21T20:07:58+00:00" }, { "name": "phpunit/php-code-coverage", @@ -2785,16 +2776,16 @@ }, { "name": "phpunit/phpunit", - "version": "8.5.32", + "version": "8.5.33", "source": { "type": "git", "url": "https://github.com/sebastianbergmann/phpunit.git", - "reference": "375686930d05c9fd7d20f6e5fc38121e8d7a9d55" + "reference": "7d1ff0e8c6b35db78ff13e3e05517d7cbf7aa32e" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/sebastianbergmann/phpunit/zipball/375686930d05c9fd7d20f6e5fc38121e8d7a9d55", - "reference": "375686930d05c9fd7d20f6e5fc38121e8d7a9d55", + "url": "https://api.github.com/repos/sebastianbergmann/phpunit/zipball/7d1ff0e8c6b35db78ff13e3e05517d7cbf7aa32e", + "reference": "7d1ff0e8c6b35db78ff13e3e05517d7cbf7aa32e", "shasum": "" }, "require": { @@ -2862,7 +2853,7 @@ ], "support": { "issues": "https://github.com/sebastianbergmann/phpunit/issues", - "source": "https://github.com/sebastianbergmann/phpunit/tree/8.5.32" + "source": "https://github.com/sebastianbergmann/phpunit/tree/8.5.33" }, "funding": [ { @@ -2878,7 +2869,7 @@ "type": "tidelift" } ], - "time": "2023-01-26T08:30:25+00:00" + "time": "2023-02-27T13:04:50+00:00" }, { "name": "psr/cache", @@ -3309,16 +3300,16 @@ }, { "name": "sebastian/diff", - "version": "3.0.3", + "version": "3.0.4", "source": { "type": "git", "url": "https://github.com/sebastianbergmann/diff.git", - "reference": "14f72dd46eaf2f2293cbe79c93cc0bc43161a211" + "reference": "6296a0c086dd0117c1b78b059374d7fcbe7545ae" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/sebastianbergmann/diff/zipball/14f72dd46eaf2f2293cbe79c93cc0bc43161a211", - "reference": "14f72dd46eaf2f2293cbe79c93cc0bc43161a211", + "url": "https://api.github.com/repos/sebastianbergmann/diff/zipball/6296a0c086dd0117c1b78b059374d7fcbe7545ae", + "reference": "6296a0c086dd0117c1b78b059374d7fcbe7545ae", "shasum": "" }, "require": { @@ -3363,7 +3354,7 @@ ], "support": { "issues": "https://github.com/sebastianbergmann/diff/issues", - "source": "https://github.com/sebastianbergmann/diff/tree/3.0.3" + "source": "https://github.com/sebastianbergmann/diff/tree/3.0.4" }, "funding": [ { @@ -3371,7 +3362,7 @@ "type": "github" } ], - "time": "2020-11-30T07:59:04+00:00" + "time": "2023-05-07T05:30:20+00:00" }, { "name": "sebastian/environment", @@ -3909,16 +3900,16 @@ }, { "name": "symfony/console", - "version": "v5.4.19", + "version": "v5.4.24", "source": { "type": "git", "url": "https://github.com/symfony/console.git", - "reference": "dccb8d251a9017d5994c988b034d3e18aaabf740" + "reference": "560fc3ed7a43e6d30ea94a07d77f9a60b8ed0fb8" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/symfony/console/zipball/dccb8d251a9017d5994c988b034d3e18aaabf740", - "reference": "dccb8d251a9017d5994c988b034d3e18aaabf740", + "url": "https://api.github.com/repos/symfony/console/zipball/560fc3ed7a43e6d30ea94a07d77f9a60b8ed0fb8", + "reference": "560fc3ed7a43e6d30ea94a07d77f9a60b8ed0fb8", "shasum": "" }, "require": { @@ -3983,12 +3974,12 @@ "homepage": "https://symfony.com", "keywords": [ "cli", - "command line", + "command-line", "console", "terminal" ], "support": { - "source": "https://github.com/symfony/console/tree/v5.4.19" + "source": "https://github.com/symfony/console/tree/v5.4.24" }, "funding": [ { @@ -4004,20 +3995,20 @@ "type": "tidelift" } ], - "time": "2023-01-01T08:32:19+00:00" + "time": "2023-05-26T05:13:16+00:00" }, { "name": "symfony/event-dispatcher", - "version": "v5.4.19", + "version": "v5.4.22", "source": { "type": "git", "url": "https://github.com/symfony/event-dispatcher.git", - "reference": "abf49cc084c087d94b4cb939c3f3672971784e0c" + "reference": "1df20e45d56da29a4b1d8259dd6e950acbf1b13f" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/symfony/event-dispatcher/zipball/abf49cc084c087d94b4cb939c3f3672971784e0c", - "reference": "abf49cc084c087d94b4cb939c3f3672971784e0c", + "url": "https://api.github.com/repos/symfony/event-dispatcher/zipball/1df20e45d56da29a4b1d8259dd6e950acbf1b13f", + "reference": "1df20e45d56da29a4b1d8259dd6e950acbf1b13f", "shasum": "" }, "require": { @@ -4073,7 +4064,7 @@ "description": "Provides tools that allow your application components to communicate with each other by dispatching events and listening to them", "homepage": "https://symfony.com", "support": { - "source": "https://github.com/symfony/event-dispatcher/tree/v5.4.19" + "source": "https://github.com/symfony/event-dispatcher/tree/v5.4.22" }, "funding": [ { @@ -4089,7 +4080,7 @@ "type": "tidelift" } ], - "time": "2023-01-01T08:32:19+00:00" + "time": "2023-03-17T11:31:58+00:00" }, { "name": "symfony/event-dispatcher-contracts", @@ -4172,16 +4163,16 @@ }, { "name": "symfony/filesystem", - "version": "v5.4.19", + "version": "v5.4.23", "source": { "type": "git", "url": "https://github.com/symfony/filesystem.git", - "reference": "648bfaca6a494f3e22378123bcee2894045dc9d8" + "reference": "b2f79d86cd9e7de0fff6d03baa80eaed7a5f38b5" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/symfony/filesystem/zipball/648bfaca6a494f3e22378123bcee2894045dc9d8", - "reference": "648bfaca6a494f3e22378123bcee2894045dc9d8", + "url": "https://api.github.com/repos/symfony/filesystem/zipball/b2f79d86cd9e7de0fff6d03baa80eaed7a5f38b5", + "reference": "b2f79d86cd9e7de0fff6d03baa80eaed7a5f38b5", "shasum": "" }, "require": { @@ -4216,7 +4207,7 @@ "description": "Provides basic utilities for the filesystem", "homepage": "https://symfony.com", "support": { - "source": "https://github.com/symfony/filesystem/tree/v5.4.19" + "source": "https://github.com/symfony/filesystem/tree/v5.4.23" }, "funding": [ { @@ -4232,20 +4223,20 @@ "type": "tidelift" } ], - "time": "2023-01-14T19:14:44+00:00" + "time": "2023-03-02T11:38:35+00:00" }, { "name": "symfony/finder", - "version": "v5.4.19", + "version": "v5.4.21", "source": { "type": "git", "url": "https://github.com/symfony/finder.git", - "reference": "6071aebf810ad13fe8200c224f36103abb37cf1f" + "reference": "078e9a5e1871fcfe6a5ce421b539344c21afef19" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/symfony/finder/zipball/6071aebf810ad13fe8200c224f36103abb37cf1f", - "reference": "6071aebf810ad13fe8200c224f36103abb37cf1f", + "url": "https://api.github.com/repos/symfony/finder/zipball/078e9a5e1871fcfe6a5ce421b539344c21afef19", + "reference": "078e9a5e1871fcfe6a5ce421b539344c21afef19", "shasum": "" }, "require": { @@ -4279,7 +4270,7 @@ "description": "Finds files and directories via an intuitive fluent interface", "homepage": "https://symfony.com", "support": { - "source": "https://github.com/symfony/finder/tree/v5.4.19" + "source": "https://github.com/symfony/finder/tree/v5.4.21" }, "funding": [ { @@ -4295,7 +4286,7 @@ "type": "tidelift" } ], - "time": "2023-01-14T19:14:44+00:00" + "time": "2023-02-16T09:33:00+00:00" }, { "name": "symfony/polyfill-ctype", @@ -4871,16 +4862,16 @@ }, { "name": "symfony/process", - "version": "v5.4.19", + "version": "v5.4.24", "source": { "type": "git", "url": "https://github.com/symfony/process.git", - "reference": "c5ba874c9b636dbccf761e22ce750e88ec3f55e1" + "reference": "e3c46cc5689c8782944274bb30702106ecbe3b64" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/symfony/process/zipball/c5ba874c9b636dbccf761e22ce750e88ec3f55e1", - "reference": "c5ba874c9b636dbccf761e22ce750e88ec3f55e1", + "url": "https://api.github.com/repos/symfony/process/zipball/e3c46cc5689c8782944274bb30702106ecbe3b64", + "reference": "e3c46cc5689c8782944274bb30702106ecbe3b64", "shasum": "" }, "require": { @@ -4913,7 +4904,7 @@ "description": "Executes commands in sub-processes", "homepage": "https://symfony.com", "support": { - "source": "https://github.com/symfony/process/tree/v5.4.19" + "source": "https://github.com/symfony/process/tree/v5.4.24" }, "funding": [ { @@ -4929,7 +4920,7 @@ "type": "tidelift" } ], - "time": "2023-01-01T08:32:19+00:00" + "time": "2023-05-17T11:26:05+00:00" }, { "name": "symfony/service-contracts", @@ -5016,16 +5007,16 @@ }, { "name": "symfony/stopwatch", - "version": "v5.4.19", + "version": "v5.4.21", "source": { "type": "git", "url": "https://github.com/symfony/stopwatch.git", - "reference": "bd2b066090fd6a67039371098fa25a84cb2679ec" + "reference": "f83692cd869a6f2391691d40a01e8acb89e76fee" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/symfony/stopwatch/zipball/bd2b066090fd6a67039371098fa25a84cb2679ec", - "reference": "bd2b066090fd6a67039371098fa25a84cb2679ec", + "url": "https://api.github.com/repos/symfony/stopwatch/zipball/f83692cd869a6f2391691d40a01e8acb89e76fee", + "reference": "f83692cd869a6f2391691d40a01e8acb89e76fee", "shasum": "" }, "require": { @@ -5058,7 +5049,7 @@ "description": "Provides a way to profile code", "homepage": "https://symfony.com", "support": { - "source": "https://github.com/symfony/stopwatch/tree/v5.4.19" + "source": "https://github.com/symfony/stopwatch/tree/v5.4.21" }, "funding": [ { @@ -5074,20 +5065,20 @@ "type": "tidelift" } ], - "time": "2023-01-01T08:32:19+00:00" + "time": "2023-02-14T08:03:56+00:00" }, { "name": "symfony/string", - "version": "v5.4.19", + "version": "v5.4.22", "source": { "type": "git", "url": "https://github.com/symfony/string.git", - "reference": "0a01071610fd861cc160dfb7e2682ceec66064cb" + "reference": "8036a4c76c0dd29e60b6a7cafcacc50cf088ea62" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/symfony/string/zipball/0a01071610fd861cc160dfb7e2682ceec66064cb", - "reference": "0a01071610fd861cc160dfb7e2682ceec66064cb", + "url": "https://api.github.com/repos/symfony/string/zipball/8036a4c76c0dd29e60b6a7cafcacc50cf088ea62", + "reference": "8036a4c76c0dd29e60b6a7cafcacc50cf088ea62", "shasum": "" }, "require": { @@ -5144,7 +5135,7 @@ "utf8" ], "support": { - "source": "https://github.com/symfony/string/tree/v5.4.19" + "source": "https://github.com/symfony/string/tree/v5.4.22" }, "funding": [ { @@ -5160,7 +5151,7 @@ "type": "tidelift" } ], - "time": "2023-01-01T08:32:19+00:00" + "time": "2023-03-14T06:11:53+00:00" }, { "name": "symfony/yaml", @@ -5235,16 +5226,16 @@ }, { "name": "symplify/easy-coding-standard", - "version": "11.2.9", + "version": "11.5.0", "source": { "type": "git", "url": "https://github.com/easy-coding-standard/easy-coding-standard.git", - "reference": "947267668efb055bf78c7b68416cb206285f21d4" + "reference": "1d2400f7bfe92e3754ce71f0782f2c0521bade3d" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/easy-coding-standard/easy-coding-standard/zipball/947267668efb055bf78c7b68416cb206285f21d4", - "reference": "947267668efb055bf78c7b68416cb206285f21d4", + "url": "https://api.github.com/repos/easy-coding-standard/easy-coding-standard/zipball/1d2400f7bfe92e3754ce71f0782f2c0521bade3d", + "reference": "1d2400f7bfe92e3754ce71f0782f2c0521bade3d", "shasum": "" }, "require": { @@ -5252,7 +5243,8 @@ }, "conflict": { "friendsofphp/php-cs-fixer": "<3.0", - "squizlabs/php_codesniffer": "<3.6" + "squizlabs/php_codesniffer": "<3.6", + "symplify/coding-standard": "<11.3" }, "bin": [ "bin/ecs" @@ -5268,9 +5260,15 @@ "MIT" ], "description": "Use Coding Standard with 0-knowledge of PHP-CS-Fixer and PHP_CodeSniffer", + "keywords": [ + "Code style", + "automation", + "fixer", + "static analysis" + ], "support": { "issues": "https://github.com/easy-coding-standard/easy-coding-standard/issues", - "source": "https://github.com/easy-coding-standard/easy-coding-standard/tree/11.2.9" + "source": "https://github.com/easy-coding-standard/easy-coding-standard/tree/11.5.0" }, "funding": [ { @@ -5282,7 +5280,7 @@ "type": "github" } ], - "time": "2023-02-21T11:31:15+00:00" + "time": "2023-06-21T06:26:15+00:00" }, { "name": "theseer/tokenizer", @@ -5405,5 +5403,5 @@ "platform-overrides": { "php": "8.0" }, - "plugin-api-version": "2.3.0" + "plugin-api-version": "2.2.0" } diff --git a/phpunit.xml.dist b/phpunit.xml.dist index 027b1ff..c8fd9ed 100644 --- a/phpunit.xml.dist +++ b/phpunit.xml.dist @@ -8,7 +8,8 @@ convertNoticesToExceptions="true" convertWarningsToExceptions="true" processIsolation="false" - stopOnFailure="false"> + stopOnFailure="false" + cacheResult ="false"> tests/ diff --git a/src/AkeneoPimClientBuilder.php b/src/AkeneoPimClientBuilder.php index febc4d6..375af80 100644 --- a/src/AkeneoPimClientBuilder.php +++ b/src/AkeneoPimClientBuilder.php @@ -44,6 +44,7 @@ use Akeneo\Pim\ApiClient\Cache\LRUCache; use Akeneo\Pim\ApiClient\Client\AuthenticatedHttpClient; use Akeneo\Pim\ApiClient\Client\CachedResourceClient; +use Akeneo\Pim\ApiClient\Client\ClientInterface; use Akeneo\Pim\ApiClient\Client\HttpClient; use Akeneo\Pim\ApiClient\Client\Options; use Akeneo\Pim\ApiClient\Client\ResourceClient; @@ -57,7 +58,6 @@ use Akeneo\Pim\ApiClient\Stream\UpsertResourceListResponseFactory; use Http\Discovery\Psr17FactoryDiscovery; use Http\Discovery\Psr18ClientDiscovery; -use Psr\Http\Client\ClientInterface; use Psr\Http\Message\RequestFactoryInterface; use Psr\Http\Message\StreamFactoryInterface; @@ -295,7 +295,7 @@ protected function setUp(Authentication $authentication): array return [$resourceClient, $pageFactory, $cursorFactory, $fileSystem]; } - private function getHttpClient(): ClientInterface + private function getHttpClient(): ClientInterface|\Psr\Http\Client\ClientInterface { if (null === $this->httpClient) { $this->httpClient = Psr18ClientDiscovery::find(); diff --git a/src/Api/AppCatalog/AppCatalogApi.php b/src/Api/AppCatalog/AppCatalogApi.php index a2d52cd..c8f1681 100644 --- a/src/Api/AppCatalog/AppCatalogApi.php +++ b/src/Api/AppCatalog/AppCatalogApi.php @@ -10,6 +10,8 @@ use Akeneo\Pim\ApiClient\Pagination\PageInterface; use Akeneo\Pim\ApiClient\Pagination\ResourceCursorFactoryInterface; use Akeneo\Pim\ApiClient\Pagination\ResourceCursorInterface; +use GuzzleHttp\Promise\PromiseInterface; +use Http\Promise\Promise; /** * @copyright 2022 Akeneo SAS (https://www.akeneo.com) @@ -60,4 +62,9 @@ public function delete(string $code): int { return $this->resourceClient->deleteResource(static::APP_CATALOG_URI, [$code]); } + + public function upsertAsync(string $code, array $data = []): PromiseInterface|Promise + { + return $this->resourceClient->upsertAsyncAndReturnPromise(static::APP_CATALOG_URI, [$code], $data); + } } diff --git a/src/Api/AppCatalog/AppCatalogApiInterface.php b/src/Api/AppCatalog/AppCatalogApiInterface.php index 63e3896..8a294a8 100644 --- a/src/Api/AppCatalog/AppCatalogApiInterface.php +++ b/src/Api/AppCatalog/AppCatalogApiInterface.php @@ -7,6 +7,8 @@ use Akeneo\Pim\ApiClient\Api\Operation\DeletableResourceInterface; use Akeneo\Pim\ApiClient\Api\Operation\GettableResourceInterface; use Akeneo\Pim\ApiClient\Api\Operation\ListableResourceInterface; +use GuzzleHttp\Promise\PromiseInterface; +use Http\Promise\Promise; /** * @copyright 2022 Akeneo SAS (https://www.akeneo.com) @@ -20,4 +22,5 @@ interface AppCatalogApiInterface extends public function create(array $data): array; public function upsert(string $code, array $data = []): array; + public function upsertAsync(string $code, array $data = []): PromiseInterface|Promise; } diff --git a/src/Api/AssetApi.php b/src/Api/AssetApi.php index 83ebb94..f33215b 100644 --- a/src/Api/AssetApi.php +++ b/src/Api/AssetApi.php @@ -10,6 +10,9 @@ use Akeneo\Pim\ApiClient\Pagination\PageInterface; use Akeneo\Pim\ApiClient\Pagination\ResourceCursorFactoryInterface; use Akeneo\Pim\ApiClient\Pagination\ResourceCursorInterface; +use GuzzleHttp\Promise\PromiseInterface; +use Http\Promise\Promise; +use Psr\Http\Message\StreamInterface; /** * API implementation to manage assets. @@ -89,6 +92,11 @@ public function upsert(string $code, array $data = []): int return $this->resourceClient->upsertResource(static::ASSET_URI, [$code], $data); } + public function upsertAsync(string $code, array $data = []): PromiseInterface|Promise + { + return $this->resourceClient->upsertAsyncResource(static::ASSET_URI, [$code], $data); + } + /** * {@inheritdoc} */ @@ -96,4 +104,9 @@ public function upsertList($resources): \Traversable { return $this->resourceClient->upsertStreamResourceList(static::ASSETS_URI, [], $resources); } + + public function upsertAsyncList(StreamInterface|array $resources): PromiseInterface|Promise + { + return $this->resourceClient->upsertAsyncStreamResourceList(self::ASSETS_URI, [], $resources); + } } diff --git a/src/Api/AssetCategoryApi.php b/src/Api/AssetCategoryApi.php index 8f672d7..4d874e8 100644 --- a/src/Api/AssetCategoryApi.php +++ b/src/Api/AssetCategoryApi.php @@ -10,6 +10,9 @@ use Akeneo\Pim\ApiClient\Pagination\PageInterface; use Akeneo\Pim\ApiClient\Pagination\ResourceCursorFactoryInterface; use Akeneo\Pim\ApiClient\Pagination\ResourceCursorInterface; +use GuzzleHttp\Promise\PromiseInterface; +use Http\Promise\Promise; +use Psr\Http\Message\StreamInterface; /** * API implementation to manage asset categories. @@ -74,6 +77,11 @@ public function upsert(string $code, array $data = []): int return $this->resourceClient->upsertResource(static::ASSET_CATEGORY_URI, [$code], $data); } + public function upsertAsync(string $code, array $data = []): PromiseInterface|Promise + { + return $this->resourceClient->upsertAsyncResource(static::ASSET_CATEGORY_URI, [$code], $data); + } + /** * {@inheritdoc} */ @@ -95,4 +103,9 @@ public function create(string $code, array $data = []): int return $this->resourceClient->createResource(static::ASSET_CATEGORIES_URI, [], $data); } + + public function upsertAsyncList(StreamInterface|array $resources): PromiseInterface|Promise + { + return $this->resourceClient->upsertAsyncStreamResourceList(static::ASSET_CATEGORIES_URI, [], $resources); + } } diff --git a/src/Api/AssetManager/AssetApi.php b/src/Api/AssetManager/AssetApi.php index f939095..0df70ea 100644 --- a/src/Api/AssetManager/AssetApi.php +++ b/src/Api/AssetManager/AssetApi.php @@ -8,6 +8,8 @@ use Akeneo\Pim\ApiClient\Pagination\PageFactoryInterface; use Akeneo\Pim\ApiClient\Pagination\ResourceCursorFactoryInterface; use Akeneo\Pim\ApiClient\Pagination\ResourceCursorInterface; +use GuzzleHttp\Promise\PromiseInterface; +use Http\Promise\Promise; class AssetApi implements AssetApiInterface { @@ -70,4 +72,20 @@ public function delete(string $assetFamilyCode, string $assetCode): int { return $this->resourceClient->deleteResource(static::ASSET_URI, [$assetFamilyCode, $assetCode]); } + + /** + * {@inheritdoc} + */ + public function upsertAsync(string $assetFamilyCode, string $assetCode, array $data = []): PromiseInterface|Promise + { + return $this->resourceClient->upsertAsyncResource(static::ASSET_URI, [$assetFamilyCode, $assetCode], $data); + } + + /** + * {@inheritdoc} + */ + public function upsertAsyncList(string $assetFamilyCode, array $assets): PromiseInterface|Promise + { + return $this->resourceClient->upsertAsyncJsonResourceList(static::ASSETS_URI, [$assetFamilyCode], $assets); + } } diff --git a/src/Api/AssetManager/AssetApiInterface.php b/src/Api/AssetManager/AssetApiInterface.php index 07fe5b3..c3349d2 100644 --- a/src/Api/AssetManager/AssetApiInterface.php +++ b/src/Api/AssetManager/AssetApiInterface.php @@ -6,6 +6,8 @@ use Akeneo\Pim\ApiClient\Exception\HttpException; use Akeneo\Pim\ApiClient\Pagination\ResourceCursorInterface; +use GuzzleHttp\Promise\PromiseInterface; +use Http\Promise\Promise; interface AssetApiInterface { @@ -56,6 +58,27 @@ public function upsert(string $assetFamilyCode, string $assetCode, array $data = */ public function upsertList(string $assetFamilyCode, array $assets): array; + /** + * Creates an asset family if it does not exist yet, otherwise updates partially the asset family. + * + * @throws HttpException + * + * @return Promise + */ + public function upsertAsync(string $assetFamilyCode, string $assetCode, array $data = []): PromiseInterface|Promise; + + /** + * Updates or creates several assets. + * + * @param string $assetFamilyCode Code of the asset family + * @param array $assets Array containing the assets to create or update + * + * @throws HttpException + * + * @return Promise + */ + public function upsertAsyncList(string $assetFamilyCode, array $assets): PromiseInterface|Promise; + /** * Deletes an asset. * diff --git a/src/Api/AssetManager/AssetAttributeApi.php b/src/Api/AssetManager/AssetAttributeApi.php index d9c8eef..2d16e1c 100644 --- a/src/Api/AssetManager/AssetAttributeApi.php +++ b/src/Api/AssetManager/AssetAttributeApi.php @@ -5,6 +5,8 @@ namespace Akeneo\Pim\ApiClient\Api\AssetManager; use Akeneo\Pim\ApiClient\Client\ResourceClientInterface; +use GuzzleHttp\Promise\PromiseInterface; +use Http\Promise\Promise; class AssetAttributeApi implements AssetAttributeApiInterface { @@ -39,4 +41,12 @@ public function upsert(string $assetFamilyCode, string $attributeCode, array $da { return $this->resourceClient->upsertResource(static::ASSET_ATTRIBUTE_URI, [$assetFamilyCode, $attributeCode], $data); } + + /** + * {@inheritdoc} + */ + public function upsertAsync(string $assetFamilyCode, string $attributeCode, array $data = []): PromiseInterface|Promise + { + return $this->resourceClient->upsertAsyncResource(static::ASSET_ATTRIBUTE_URI, [$assetFamilyCode, $attributeCode], $data); + } } diff --git a/src/Api/AssetManager/AssetAttributeApiInterface.php b/src/Api/AssetManager/AssetAttributeApiInterface.php index a1ccbf7..9980f53 100644 --- a/src/Api/AssetManager/AssetAttributeApiInterface.php +++ b/src/Api/AssetManager/AssetAttributeApiInterface.php @@ -5,6 +5,8 @@ namespace Akeneo\Pim\ApiClient\Api\AssetManager; use Akeneo\Pim\ApiClient\Exception\HttpException; +use GuzzleHttp\Promise\PromiseInterface; +use Http\Promise\Promise; interface AssetAttributeApiInterface { @@ -23,7 +25,7 @@ public function get(string $assetFamilyCode, string $attributeCode): array; public function all(string $assetFamilyCode, array $queryParameters = []): array; /** - * Creates a asset attribute if it does not exist yet, otherwise updates partially the attribute. + * Creates an asset attribute if it does not exist yet, otherwise updates partially the attribute. * * @throws HttpException * @@ -31,4 +33,13 @@ public function all(string $assetFamilyCode, array $queryParameters = []): array * Status code 204 indicating that the asset attribute has been well updated. */ public function upsert(string $assetFamilyCode, string $attributeCode, array $data = []): int; + + /** + * Creates an asset attribute if it does not exist yet, otherwise updates partially the attribute. + * + * @throws HttpException + * + * @return Promise + */ + public function upsertAsync(string $assetFamilyCode, string $attributeCode, array $data = []): PromiseInterface|Promise; } diff --git a/src/Api/AssetManager/AssetAttributeOptionApi.php b/src/Api/AssetManager/AssetAttributeOptionApi.php index 062669a..46d2c70 100644 --- a/src/Api/AssetManager/AssetAttributeOptionApi.php +++ b/src/Api/AssetManager/AssetAttributeOptionApi.php @@ -5,6 +5,8 @@ namespace Akeneo\Pim\ApiClient\Api\AssetManager; use Akeneo\Pim\ApiClient\Client\ResourceClientInterface; +use GuzzleHttp\Promise\PromiseInterface; +use Http\Promise\Promise; class AssetAttributeOptionApi implements AssetAttributeOptionApiInterface { @@ -49,4 +51,20 @@ public function upsert(string $assetFamilyCode, string $attributeCode, string $a $data ); } + + /** + * {@inheritdoc} + */ + public function upsertAsync( + string $assetFamilyCode, + string $attributeCode, + string $attributeOptionCode, + array $data = [] + ): PromiseInterface|Promise { + return $this->resourceClient->upsertAsyncResource( + static::ASSET_ATTRIBUTE_OPTION_URI, + [$assetFamilyCode, $attributeCode, $attributeOptionCode], + $data + ); + } } diff --git a/src/Api/AssetManager/AssetAttributeOptionApiInterface.php b/src/Api/AssetManager/AssetAttributeOptionApiInterface.php index 510d072..96ac250 100644 --- a/src/Api/AssetManager/AssetAttributeOptionApiInterface.php +++ b/src/Api/AssetManager/AssetAttributeOptionApiInterface.php @@ -5,6 +5,8 @@ namespace Akeneo\Pim\ApiClient\Api\AssetManager; use Akeneo\Pim\ApiClient\Exception\HttpException; +use GuzzleHttp\Promise\PromiseInterface; +use Http\Promise\Promise; interface AssetAttributeOptionApiInterface { @@ -23,7 +25,7 @@ public function get(string $assetFamilyCode, string $attributeCode, string $attr public function all(string $assetFamilyCode, string $attributeCode): array; /** - * Creates a asset attribute option if it does not exist yet, otherwise updates partially the attribute option. + * Creates an asset attribute option if it does not exist yet, otherwise updates partially the attribute option. * * @throws HttpException * @@ -31,4 +33,18 @@ public function all(string $assetFamilyCode, string $attributeCode): array; * Status code 204 indicating that the asset attribute option has been well updated. */ public function upsert(string $assetFamilyCode, string $attributeCode, string $attributeOptionCode, array $data = []): int; + + /** + * Creates an asset attribute option if it does not exist yet, otherwise updates partially the attribute option. + * + * @throws HttpException + * + * @return Promise + */ + public function upsertAsync( + string $assetFamilyCode, + string $attributeCode, + string $attributeOptionCode, + array $data = [] + ): PromiseInterface|Promise; } diff --git a/src/Api/AssetManager/AssetFamilyApi.php b/src/Api/AssetManager/AssetFamilyApi.php index 8a1e3c6..ff9c602 100644 --- a/src/Api/AssetManager/AssetFamilyApi.php +++ b/src/Api/AssetManager/AssetFamilyApi.php @@ -8,6 +8,8 @@ use Akeneo\Pim\ApiClient\Pagination\PageFactoryInterface; use Akeneo\Pim\ApiClient\Pagination\ResourceCursorFactoryInterface; use Akeneo\Pim\ApiClient\Pagination\ResourceCursorInterface; +use GuzzleHttp\Promise\PromiseInterface; +use Http\Promise\Promise; class AssetFamilyApi implements AssetFamilyApiInterface { @@ -54,4 +56,12 @@ public function upsert(string $code, array $data = []): int { return $this->resourceClient->upsertResource(static::ASSET_FAMILY_URI, [$code], $data); } + + /** + * {@inheritdoc} + */ + public function upsertAsync(string $code, array $data = []): PromiseInterface|Promise + { + return $this->resourceClient->upsertAsyncResource(static::ASSET_FAMILY_URI, [$code], $data); + } } diff --git a/src/Api/AssetManager/AssetFamilyApiInterface.php b/src/Api/AssetManager/AssetFamilyApiInterface.php index e892f90..4db7607 100644 --- a/src/Api/AssetManager/AssetFamilyApiInterface.php +++ b/src/Api/AssetManager/AssetFamilyApiInterface.php @@ -6,6 +6,8 @@ use Akeneo\Pim\ApiClient\Exception\HttpException; use Akeneo\Pim\ApiClient\Pagination\ResourceCursorInterface; +use GuzzleHttp\Promise\PromiseInterface; +use Http\Promise\Promise; interface AssetFamilyApiInterface { @@ -32,4 +34,13 @@ public function all(array $queryParameters = []): ResourceCursorInterface; * Status code 204 indicating that the asset family has been well updated. */ public function upsert(string $assetFamilyCode, array $data = []): int; + + /** + * Creates an asset family if it does not exist yet, otherwise updates partially the asset family. + * + * @throws HttpException + * + * @return Promise + */ + public function upsertAsync(string $assetFamilyCode, array $data = []): PromiseInterface|Promise; } diff --git a/src/Api/AssetTagApi.php b/src/Api/AssetTagApi.php index 5749f3f..04484c1 100644 --- a/src/Api/AssetTagApi.php +++ b/src/Api/AssetTagApi.php @@ -9,6 +9,8 @@ use Akeneo\Pim\ApiClient\Pagination\PageInterface; use Akeneo\Pim\ApiClient\Pagination\ResourceCursorFactoryInterface; use Akeneo\Pim\ApiClient\Pagination\ResourceCursorInterface; +use GuzzleHttp\Promise\PromiseInterface; +use Http\Promise\Promise; /** * API implementation to manage asset tags. @@ -71,4 +73,9 @@ public function listPerPage(int $limit = 100, bool $withCount = false, array $qu return $this->pageFactory->createPage($data); } + + public function upsertAsync(string $code, array $data = []): PromiseInterface|Promise + { + return $this->resourceClient->upsertAsyncResource(static::ASSET_TAG_URI, [$code], $data); + } } diff --git a/src/Api/AssociationTypeApi.php b/src/Api/AssociationTypeApi.php index 5447c24..7ea8fa4 100644 --- a/src/Api/AssociationTypeApi.php +++ b/src/Api/AssociationTypeApi.php @@ -8,6 +8,9 @@ use Akeneo\Pim\ApiClient\Pagination\PageInterface; use Akeneo\Pim\ApiClient\Pagination\ResourceCursorFactoryInterface; use Akeneo\Pim\ApiClient\Pagination\ResourceCursorInterface; +use GuzzleHttp\Promise\PromiseInterface; +use Http\Promise\Promise; +use Psr\Http\Message\StreamInterface; /** * @author Philippe Mossière @@ -75,6 +78,11 @@ public function upsert(string $code, array $data = []): int return $this->resourceClient->upsertResource(static::ASSOCIATION_TYPE_URI, [$code], $data); } + public function upsertAsync(string $code, array $data = []): PromiseInterface|Promise + { + return $this->resourceClient->upsertAsyncResource(static::ASSOCIATION_TYPE_URI, [$code], $data); + } + /** * {@inheritdoc} */ @@ -82,4 +90,9 @@ public function upsertList($resources): \Traversable { return $this->resourceClient->upsertStreamResourceList(static::ASSOCIATION_TYPES_URI, [], $resources); } + + public function upsertAsyncList(StreamInterface|array $resources): PromiseInterface|Promise + { + return $this->resourceClient->upsertAsyncStreamResourceList(static::ASSOCIATION_TYPES_URI, [], $resources); + } } diff --git a/src/Api/AttributeApi.php b/src/Api/AttributeApi.php index baab98f..7ce663e 100644 --- a/src/Api/AttributeApi.php +++ b/src/Api/AttributeApi.php @@ -8,6 +8,9 @@ use Akeneo\Pim\ApiClient\Pagination\PageInterface; use Akeneo\Pim\ApiClient\Pagination\ResourceCursorFactoryInterface; use Akeneo\Pim\ApiClient\Pagination\ResourceCursorInterface; +use GuzzleHttp\Promise\PromiseInterface; +use Http\Promise\Promise; +use Psr\Http\Message\StreamInterface; /** * API implementation to manage the attributes. @@ -78,6 +81,11 @@ public function upsert(string $code, array $data = []): int return $this->resourceClient->upsertResource(static::ATTRIBUTE_URI, [$code], $data); } + public function upsertAsync(string $code, array $data = []): PromiseInterface|Promise + { + return $this->resourceClient->upsertAsyncResource(static::ATTRIBUTE_URI, [$code], $data); + } + /** * {@inheritdoc} */ @@ -85,4 +93,9 @@ public function upsertList($resources): \Traversable { return $this->resourceClient->upsertStreamResourceList(static::ATTRIBUTES_URI, [], $resources); } + + public function upsertAsyncList(StreamInterface|array $resources): PromiseInterface|Promise + { + return $this->resourceClient->upsertAsyncStreamResourceList(static::ATTRIBUTES_URI, [], $resources); + } } diff --git a/src/Api/AttributeGroupApi.php b/src/Api/AttributeGroupApi.php index 78db294..bb4d763 100644 --- a/src/Api/AttributeGroupApi.php +++ b/src/Api/AttributeGroupApi.php @@ -8,6 +8,9 @@ use Akeneo\Pim\ApiClient\Pagination\PageInterface; use Akeneo\Pim\ApiClient\Pagination\ResourceCursorFactoryInterface; use Akeneo\Pim\ApiClient\Pagination\ResourceCursorInterface; +use GuzzleHttp\Promise\PromiseInterface; +use Http\Promise\Promise; +use Psr\Http\Message\StreamInterface; /** * API implementation to manage attribute groups. @@ -78,6 +81,11 @@ public function upsert(string $code, array $data = []): int return $this->resourceClient->upsertResource(static::ATTRIBUTE_GROUP_URI, [$code], $data); } + public function upsertAsync(string $code, array $data = []): PromiseInterface|Promise + { + return $this->resourceClient->upsertAsyncResource(static::ATTRIBUTE_GROUP_URI, [$code], $data); + } + /** * {@inheritdoc} */ @@ -85,4 +93,9 @@ public function upsertList($resources): \Traversable { return $this->resourceClient->upsertStreamResourceList(static::ATTRIBUTE_GROUPS_URI, [], $resources); } + + public function upsertAsyncList(StreamInterface|array $resources): PromiseInterface|Promise + { + return $this->resourceClient->upsertAsyncStreamResourceList(static::ATTRIBUTE_GROUPS_URI, [], $resources); + } } diff --git a/src/Api/AttributeOptionApi.php b/src/Api/AttributeOptionApi.php index fd61a6c..9e141bc 100644 --- a/src/Api/AttributeOptionApi.php +++ b/src/Api/AttributeOptionApi.php @@ -8,6 +8,8 @@ use Akeneo\Pim\ApiClient\Pagination\PageInterface; use Akeneo\Pim\ApiClient\Pagination\ResourceCursorFactoryInterface; use Akeneo\Pim\ApiClient\Pagination\ResourceCursorInterface; +use GuzzleHttp\Promise\PromiseInterface; +use Http\Promise\Promise; /** * API implementation to manage the attribute options. @@ -91,4 +93,20 @@ public function upsertList($attributeCode, $attributeOptions): \Traversable { return $this->resourceClient->upsertStreamResourceList(static::ATTRIBUTE_OPTIONS_URI, [$attributeCode], $attributeOptions); } + + /** + * {@inheritdoc} + */ + public function upsertAsyncList($attributeCode, $attributeOptions): PromiseInterface|Promise + { + return $this->resourceClient->upsertAsyncStreamResourceList(static::ATTRIBUTE_OPTIONS_URI, [$attributeCode], $attributeOptions); + } + + /** + * {@inheritdoc} + */ + public function upsertAsync($attributeCode, $attributeOptionCode, array $data = []): PromiseInterface|Promise + { + return $this->resourceClient->upsertAsyncResource(static::ATTRIBUTE_OPTION_URI, [$attributeCode, $attributeOptionCode], $data); + } } diff --git a/src/Api/AttributeOptionApiInterface.php b/src/Api/AttributeOptionApiInterface.php index f8b9429..5f17f68 100644 --- a/src/Api/AttributeOptionApiInterface.php +++ b/src/Api/AttributeOptionApiInterface.php @@ -6,6 +6,9 @@ use Akeneo\Pim\ApiClient\Exception\InvalidArgumentException; use Akeneo\Pim\ApiClient\Pagination\PageInterface; use Akeneo\Pim\ApiClient\Pagination\ResourceCursorInterface; +use GuzzleHttp\Promise\PromiseInterface; +use Http\Promise\Promise; +use Psr\Http\Message\StreamInterface; /** * API to manage the attribute options. @@ -86,6 +89,19 @@ public function create($attributeCode, $attributeOptionCode, array $data = []): */ public function upsert($attributeCode, $attributeOptionCode, array $data = []): int; + /** + * Creates an attribute option if it does not exist yet, otherwise updates partially the attribute option. + * + * @param string $attributeCode code of the attribute + * @param string $attributeOptionCode code of the attribute option to create or update + * @param array $data data of the attribute option to create or update + * + * @throws HttpException + * + * @return Promise + */ + public function upsertAsync($attributeCode, $attributeOptionCode, array $data = []): PromiseInterface|Promise; + /** * Updates or creates several attribute options at once. * @@ -97,4 +113,16 @@ public function upsert($attributeCode, $attributeOptionCode, array $data = []): * @return \Traversable returns an iterable object, each entry corresponding to the response of the upserted attribute options */ public function upsertList($attributeCode, $attributeOptions): \Traversable; + + /** + * Updates or creates several attribute options at once. + * + * @param string $attributeCode code of the attribute + * @param array|StreamInterface $attributeOptions array or StreamInterface object containing data of the attribute options to create or update + * + * @throws HttpException + * + * @return Promise + */ + public function upsertAsyncList($attributeCode, $attributeOptions): PromiseInterface|Promise; } diff --git a/src/Api/CategoryApi.php b/src/Api/CategoryApi.php index 95d9d52..26bfec1 100644 --- a/src/Api/CategoryApi.php +++ b/src/Api/CategoryApi.php @@ -8,6 +8,9 @@ use Akeneo\Pim\ApiClient\Pagination\PageInterface; use Akeneo\Pim\ApiClient\Pagination\ResourceCursorFactoryInterface; use Akeneo\Pim\ApiClient\Pagination\ResourceCursorInterface; +use GuzzleHttp\Promise\PromiseInterface; +use Http\Promise\Promise; +use Psr\Http\Message\StreamInterface; /** * API implementation to manage the categories. @@ -78,6 +81,11 @@ public function upsert(string $code, array $data = []): int return $this->resourceClient->upsertResource(static::CATEGORY_URI, [$code], $data); } + public function upsertAsync(string $code, array $data = []): PromiseInterface|Promise + { + return $this->resourceClient->upsertAsyncResource(static::CATEGORY_URI, [$code], $data); + } + /** * {@inheritdoc} */ @@ -85,4 +93,9 @@ public function upsertList($resources): \Traversable { return $this->resourceClient->upsertStreamResourceList(static::CATEGORIES_URI, [], $resources); } + + public function upsertAsyncList(StreamInterface|array $resources): PromiseInterface|Promise + { + return $this->resourceClient->upsertAsyncStreamResourceList(static::CATEGORIES_URI, [], $resources); + } } diff --git a/src/Api/ChannelApi.php b/src/Api/ChannelApi.php index de885da..b099b76 100644 --- a/src/Api/ChannelApi.php +++ b/src/Api/ChannelApi.php @@ -8,6 +8,9 @@ use Akeneo\Pim\ApiClient\Pagination\PageInterface; use Akeneo\Pim\ApiClient\Pagination\ResourceCursorFactoryInterface; use Akeneo\Pim\ApiClient\Pagination\ResourceCursorInterface; +use GuzzleHttp\Promise\PromiseInterface; +use Http\Promise\Promise; +use Psr\Http\Message\StreamInterface; /** * API implementation to manage the channels. @@ -78,6 +81,11 @@ public function upsert(string $code, array $data = []): int return $this->resourceClient->upsertResource(static::CHANNEL_URI, [$code], $data); } + public function upsertAsync(string $code, array $data = []): PromiseInterface|Promise + { + return $this->resourceClient->upsertAsyncResource(static::CHANNEL_URI, [$code], $data); + } + /** * {@inheritdoc} */ @@ -85,4 +93,9 @@ public function upsertList($resources): \Traversable { return $this->resourceClient->upsertStreamResourceList(static::CHANNELS_URI, [], $resources); } + + public function upsertAsyncList(StreamInterface|array $resources): PromiseInterface|Promise + { + return $this->resourceClient->upsertAsyncStreamResourceList(static::CHANNELS_URI, [], $resources); + } } diff --git a/src/Api/FamilyApi.php b/src/Api/FamilyApi.php index 4a82b1a..255497c 100644 --- a/src/Api/FamilyApi.php +++ b/src/Api/FamilyApi.php @@ -8,6 +8,9 @@ use Akeneo\Pim\ApiClient\Pagination\PageInterface; use Akeneo\Pim\ApiClient\Pagination\ResourceCursorFactoryInterface; use Akeneo\Pim\ApiClient\Pagination\ResourceCursorInterface; +use GuzzleHttp\Promise\PromiseInterface; +use Http\Promise\Promise; +use Psr\Http\Message\StreamInterface; /** * API implementation to manage the families. @@ -78,6 +81,11 @@ public function upsert(string $code, array $data = []): int return $this->resourceClient->upsertResource(static::FAMILY_URI, [$code], $data); } + public function upsertAsync(string $code, array $data = []): PromiseInterface|Promise + { + return $this->resourceClient->upsertAsyncResource(static::FAMILY_URI, [$code], $data); + } + /** * {@inheritdoc} */ @@ -85,4 +93,9 @@ public function upsertList($resources): \Traversable { return $this->resourceClient->upsertStreamResourceList(static::FAMILIES_URI, [], $resources); } + + public function upsertAsyncList(StreamInterface|array $resources): PromiseInterface|Promise + { + return $this->resourceClient->upsertAsyncStreamResourceList(static::FAMILIES_URI, [], $resources); + } } diff --git a/src/Api/FamilyVariantApi.php b/src/Api/FamilyVariantApi.php index 14917d2..84d238c 100644 --- a/src/Api/FamilyVariantApi.php +++ b/src/Api/FamilyVariantApi.php @@ -8,6 +8,8 @@ use Akeneo\Pim\ApiClient\Pagination\PageInterface; use Akeneo\Pim\ApiClient\Pagination\ResourceCursorFactoryInterface; use Akeneo\Pim\ApiClient\Pagination\ResourceCursorInterface; +use GuzzleHttp\Promise\PromiseInterface; +use Http\Promise\Promise; /** * Api implementation to manages Family Variants @@ -101,4 +103,28 @@ public function upsertList($familyCode, $familyVariants): \Traversable { return $this->resourceClient->upsertStreamResourceList(static::FAMILY_VARIANTS_URI, [$familyCode], $familyVariants); } + + /** + * {@inheritdoc} + */ + public function upsertAsync($familyCode, $familyVariantCode, array $data = []): PromiseInterface|Promise + { + if (array_key_exists('family', $data)) { + throw new InvalidArgumentException('The parameter "family" must not be defined in the data parameter'); + } + if (array_key_exists('code', $data)) { + throw new InvalidArgumentException('The parameter "code" must not be defined in the data parameter'); + } + $data['code'] = $familyVariantCode; + + return $this->resourceClient->upsertAsyncResource(static::FAMILY_VARIANT_URI, [$familyCode, $familyVariantCode], $data); + } + + /** + * {@inheritdoc} + */ + public function upsertAsyncList($familyCode, $familyVariants): PromiseInterface|Promise + { + return $this->resourceClient->upsertAsyncStreamResourceList(static::FAMILY_VARIANTS_URI, [$familyCode], $familyVariants); + } } diff --git a/src/Api/FamilyVariantApiInterface.php b/src/Api/FamilyVariantApiInterface.php index 77f59b1..723b305 100644 --- a/src/Api/FamilyVariantApiInterface.php +++ b/src/Api/FamilyVariantApiInterface.php @@ -6,6 +6,8 @@ use Akeneo\Pim\ApiClient\Exception\InvalidArgumentException; use Akeneo\Pim\ApiClient\Pagination\PageInterface; use Akeneo\Pim\ApiClient\Pagination\ResourceCursorInterface; +use GuzzleHttp\Promise\PromiseInterface; +use Http\Promise\Promise; use Psr\Http\Message\StreamInterface; /** @@ -61,6 +63,21 @@ public function create($familyCode, $familyVariantCode, array $data = []): int; */ public function upsert($familyCode, $familyVariantCode, array $data = []): int; + /** + * Available since Akeneo PIM 2.0. + * Creates a family variant if it does not exist yet, otherwise updates it partially. + * + * @param string $familyCode code of the family parent of the family variant to create or update + * @param string $familyVariantCode code of the family variant to create or update + * @param array $data data of the family variant to create or update + * + * @throws HttpException If the request failed. + * @throws InvalidArgumentException If the parameter "familyCode" is defined in the data parameter. + * + * @return Promise + */ + public function upsertAsync($familyCode, $familyVariantCode, array $data = []): PromiseInterface|Promise; + /** * Available since Akeneo PIM 2.0. * Gets a list of family variants by returning the first page. @@ -106,4 +123,17 @@ public function all($familyCode, $pageSize = 10, array $queryParameters = []): R * @return \Traversable returns an iterable object, each entry corresponding to the response of the upserted resource */ public function upsertList($familyCode, $familyVariants): \Traversable; + + /** + * Available since Akeneo PIM 2.0. + * Updates or creates several resources. + * + * @param string $familyCode code of the family parent of family variants to create or update + * @param array|StreamInterface $familyVariants array or StreamInterface object containing the family variants to create or update + * + * @throws HttpException + * + * @return Promise + */ + public function upsertAsyncList($familyCode, $familyVariants): PromiseInterface|Promise; } diff --git a/src/Api/Operation/UpsertableResourceInterface.php b/src/Api/Operation/UpsertableResourceInterface.php index ab03e36..10fcb3a 100644 --- a/src/Api/Operation/UpsertableResourceInterface.php +++ b/src/Api/Operation/UpsertableResourceInterface.php @@ -3,6 +3,8 @@ namespace Akeneo\Pim\ApiClient\Api\Operation; use Akeneo\Pim\ApiClient\Exception\HttpException; +use GuzzleHttp\Promise\PromiseInterface; +use Http\Promise\Promise; /** * API that can "upsert" a resource. @@ -25,4 +27,16 @@ interface UpsertableResourceInterface * Status code 204 indicating that the resource has been well updated. */ public function upsert(string $code, array $data = []): int; + + /** + * Creates a resource if it does not exist yet, otherwise updates partially the resource. + * + * @param string $code code of the resource to create or update + * @param array $data data of the resource to create or update + * + * @throws HttpException If the request failed. + * + * @return Promise + */ + public function upsertAsync(string $code, array $data = []): PromiseInterface|Promise; } diff --git a/src/Api/Operation/UpsertableResourceListInterface.php b/src/Api/Operation/UpsertableResourceListInterface.php index 0f19fae..6b9284c 100644 --- a/src/Api/Operation/UpsertableResourceListInterface.php +++ b/src/Api/Operation/UpsertableResourceListInterface.php @@ -3,6 +3,8 @@ namespace Akeneo\Pim\ApiClient\Api\Operation; use Akeneo\Pim\ApiClient\Exception\HttpException; +use GuzzleHttp\Promise\PromiseInterface; +use Http\Promise\Promise; use Psr\Http\Message\StreamInterface; /** @@ -24,4 +26,15 @@ interface UpsertableResourceListInterface * @return \Traversable returns an iterable object, each entry corresponding to the response of the upserted resource */ public function upsertList(array|StreamInterface $resources): \Traversable; + + /** + * Updates or creates several resources. + * + * @param array|StreamInterface $resources array or StreamInterface object containing the resources to create or update + * + * @throws HttpException + * + * @return PromiseInterface|Promise returns a Promise + */ + public function upsertAsyncList(array|StreamInterface $resources): PromiseInterface|Promise; } diff --git a/src/Api/ProductApi.php b/src/Api/ProductApi.php index 7ea5368..e8956b4 100644 --- a/src/Api/ProductApi.php +++ b/src/Api/ProductApi.php @@ -8,6 +8,9 @@ use Akeneo\Pim\ApiClient\Pagination\PageInterface; use Akeneo\Pim\ApiClient\Pagination\ResourceCursorFactoryInterface; use Akeneo\Pim\ApiClient\Pagination\ResourceCursorInterface; +use GuzzleHttp\Promise\PromiseInterface; +use Http\Promise\Promise; +use Psr\Http\Message\StreamInterface; /** * API implementation to manage the products. @@ -80,6 +83,11 @@ public function upsert(string $code, array $data = []): int return $this->resourceClient->upsertResource(static::PRODUCT_URI, [$code], $data); } + public function upsertAsync(string $code, array $data = []): PromiseInterface|Promise + { + return $this->resourceClient->upsertAsyncResource(static::PRODUCT_URI, [$code], $data); + } + /** * {@inheritdoc} */ @@ -95,4 +103,9 @@ public function upsertList($resources): \Traversable { return $this->resourceClient->upsertStreamResourceList(static::PRODUCTS_URI, [], $resources); } + + public function upsertAsyncList(StreamInterface|array $resources): PromiseInterface|Promise + { + return $this->resourceClient->upsertAsyncStreamResourceList(static::PRODUCTS_URI, [], $resources); + } } diff --git a/src/Api/ProductModelApi.php b/src/Api/ProductModelApi.php index 6c3e19e..2fcc56e 100644 --- a/src/Api/ProductModelApi.php +++ b/src/Api/ProductModelApi.php @@ -8,6 +8,9 @@ use Akeneo\Pim\ApiClient\Pagination\PageInterface; use Akeneo\Pim\ApiClient\Pagination\ResourceCursorFactoryInterface; use Akeneo\Pim\ApiClient\Pagination\ResourceCursorInterface; +use GuzzleHttp\Promise\PromiseInterface; +use Http\Promise\Promise; +use Psr\Http\Message\StreamInterface; /** * API implementation to manage the product models. @@ -113,4 +116,20 @@ public function delete(string $code): int { return $this->resourceClient->deleteResource(static::PRODUCT_MODEL_URI, [$code]); } + + public function upsertAsync(string $code, array $data = []): PromiseInterface|Promise + { + if (array_key_exists('code', $data)) { + throw new InvalidArgumentException('The parameter "code" must not be defined in the data parameter'); + } + + $data['code'] = $code; + + return $this->resourceClient->upsertAsyncResource(static::PRODUCT_MODEL_URI, [$code], $data); + } + + public function upsertAsyncList(StreamInterface|array $resources): PromiseInterface|Promise + { + return $this->resourceClient->upsertAsyncStreamResourceList(static::PRODUCT_MODELS_URI, [], $resources); + } } diff --git a/src/Api/ProductUuidApi.php b/src/Api/ProductUuidApi.php index 5a316cf..5456b93 100644 --- a/src/Api/ProductUuidApi.php +++ b/src/Api/ProductUuidApi.php @@ -10,6 +10,9 @@ use Akeneo\Pim\ApiClient\Pagination\PageInterface; use Akeneo\Pim\ApiClient\Pagination\ResourceCursorFactoryInterface; use Akeneo\Pim\ApiClient\Pagination\ResourceCursorInterface; +use GuzzleHttp\Promise\PromiseInterface; +use Http\Promise\Promise; +use Psr\Http\Message\StreamInterface; /** * @copyright 2022 Akeneo SAS (https://www.akeneo.com) @@ -63,6 +66,11 @@ public function upsert(string $uuid, array $data = []): int return $this->resourceClient->upsertResource(static::PRODUCT_UUID_URI, [$uuid], $data); } + public function upsertAsync(string $uuid, array $data = []): PromiseInterface|Promise + { + return $this->resourceClient->upsertAsyncResource(static::PRODUCT_UUID_URI, [$uuid], $data); + } + public function delete(string $uuid): int { return $this->resourceClient->deleteResource(static::PRODUCT_UUID_URI, [$uuid]); @@ -72,4 +80,9 @@ public function upsertList($resources): \Traversable { return $this->resourceClient->upsertStreamResourceList(static::PRODUCTS_UUID_URI, [], $resources); } + + public function upsertAsyncList(StreamInterface|array $resources): PromiseInterface|Promise + { + return $this->resourceClient->upsertAsyncStreamResourceList(static::PRODUCTS_UUID_URI, [], $resources); + } } diff --git a/src/Api/ProductUuidApiInterface.php b/src/Api/ProductUuidApiInterface.php index 858e2db..cfa60de 100644 --- a/src/Api/ProductUuidApiInterface.php +++ b/src/Api/ProductUuidApiInterface.php @@ -6,6 +6,8 @@ use Akeneo\Pim\ApiClient\Api\Operation\ListableResourceInterface; use Akeneo\Pim\ApiClient\Api\Operation\UpsertableResourceListInterface; +use GuzzleHttp\Promise\PromiseInterface; +use Http\Promise\Promise; /** * @copyright 2022 Akeneo SAS (https://www.akeneo.com) @@ -19,5 +21,7 @@ public function create(string $uuid, array $data = []): int; public function upsert(string $uuid, array $data = []): int; + public function upsertAsync(string $uuid, array $data = []): PromiseInterface|Promise; + public function delete(string $uuid): int; } diff --git a/src/Api/ReferenceEntityApi.php b/src/Api/ReferenceEntityApi.php index 11a440e..6ff8f88 100644 --- a/src/Api/ReferenceEntityApi.php +++ b/src/Api/ReferenceEntityApi.php @@ -8,6 +8,8 @@ use Akeneo\Pim\ApiClient\Pagination\PageFactoryInterface; use Akeneo\Pim\ApiClient\Pagination\ResourceCursorFactoryInterface; use Akeneo\Pim\ApiClient\Pagination\ResourceCursorInterface; +use GuzzleHttp\Promise\PromiseInterface; +use Http\Promise\Promise; /** * @author Tamara Robichet @@ -59,4 +61,9 @@ public function upsert(string $referenceEntityCode, array $data = []): int { return $this->resourceClient->upsertResource(static::REFERENCE_ENTITY_URI, [$referenceEntityCode], $data); } + + public function upsertAsync(string $referenceEntityCode, array $data = []): PromiseInterface|Promise + { + return $this->resourceClient->upsertAsyncResource(static::REFERENCE_ENTITY_URI, [$referenceEntityCode], $data); + } } diff --git a/src/Api/ReferenceEntityApiInterface.php b/src/Api/ReferenceEntityApiInterface.php index 2e085ad..8bd151b 100644 --- a/src/Api/ReferenceEntityApiInterface.php +++ b/src/Api/ReferenceEntityApiInterface.php @@ -6,9 +6,11 @@ use Akeneo\Pim\ApiClient\Exception\HttpException; use Akeneo\Pim\ApiClient\Pagination\ResourceCursorInterface; +use GuzzleHttp\Promise\PromiseInterface; +use Http\Promise\Promise; /** - * API to mange the reference entities. + * API to manage the reference entities. * * @author Tamara Robichet * @copyright 2018 Akeneo SAS (http://www.akeneo.com) @@ -50,4 +52,16 @@ public function all(array $queryParameters = []): ResourceCursorInterface; * Status code 204 indicating that the reference entity has been well updated. */ public function upsert(string $referenceEntityCode, array $data = []): int; + + /** + * Creates a reference entity if it does not exist yet, otherwise updates partially the reference entity. + * + * @param string $referenceEntityCode Code of the reference entity + * @param array $data Data of the reference entity to create or update + * + * @throws HttpException If the request failed. + * + * @return Promise + */ + public function upsertAsync(string $referenceEntityCode, array $data = []): PromiseInterface|Promise; } diff --git a/src/Api/ReferenceEntityAttributeApi.php b/src/Api/ReferenceEntityAttributeApi.php index b5e0819..ad3eec3 100644 --- a/src/Api/ReferenceEntityAttributeApi.php +++ b/src/Api/ReferenceEntityAttributeApi.php @@ -5,6 +5,8 @@ namespace Akeneo\Pim\ApiClient\Api; use Akeneo\Pim\ApiClient\Client\ResourceClientInterface; +use GuzzleHttp\Promise\PromiseInterface; +use Http\Promise\Promise; /** * @author Laurent Petard @@ -44,4 +46,16 @@ public function upsert(string $referenceEntityCode, string $attributeCode, array { return $this->resourceClient->upsertResource(static::REFERENCE_ENTITY_ATTRIBUTE_URI, [$referenceEntityCode, $attributeCode], $data); } + + /** + * {@inheritdoc} + */ + public function upsertAsync(string $referenceEntityCode, string $attributeCode, array $data = []): PromiseInterface|Promise + { + return $this->resourceClient->upsertAsyncResource( + static::REFERENCE_ENTITY_ATTRIBUTE_URI, + [$referenceEntityCode, $attributeCode], + $data + ); + } } diff --git a/src/Api/ReferenceEntityAttributeApiInterface.php b/src/Api/ReferenceEntityAttributeApiInterface.php index 04b7f11..d72387e 100644 --- a/src/Api/ReferenceEntityAttributeApiInterface.php +++ b/src/Api/ReferenceEntityAttributeApiInterface.php @@ -5,6 +5,8 @@ namespace Akeneo\Pim\ApiClient\Api; use Akeneo\Pim\ApiClient\Exception\HttpException; +use GuzzleHttp\Promise\PromiseInterface; +use Http\Promise\Promise; /** * @author Laurent Petard @@ -50,4 +52,17 @@ public function all(string $referenceEntityCode, array $queryParameters = []): a * Status code 204 indicating that the reference entity attribute has been well updated. */ public function upsert(string $referenceEntityCode, string $attributeCode, array $data = []): int; + + /** + * Creates a reference entity attribute if it does not exist yet, otherwise updates partially the attribute. + * + * @param string $referenceEntityCode Code of the reference entity + * @param string $attributeCode Code of the attribute + * @param array $data Data of the attribute to create or update + * + * @throws HttpException If the request failed. + * + * @return Promise + */ + public function upsertAsync(string $referenceEntityCode, string $attributeCode, array $data = []): PromiseInterface|Promise; } diff --git a/src/Api/ReferenceEntityAttributeOptionApi.php b/src/Api/ReferenceEntityAttributeOptionApi.php index 29729d1..30cf94d 100644 --- a/src/Api/ReferenceEntityAttributeOptionApi.php +++ b/src/Api/ReferenceEntityAttributeOptionApi.php @@ -5,6 +5,8 @@ namespace Akeneo\Pim\ApiClient\Api; use Akeneo\Pim\ApiClient\Client\ResourceClientInterface; +use GuzzleHttp\Promise\PromiseInterface; +use Http\Promise\Promise; /** * @author Laurent Petard @@ -54,4 +56,20 @@ public function upsert(string $referenceEntityCode, string $attributeCode, strin $data ); } + + /** + * {@inheritdoc} + */ + public function upsertAsync( + string $referenceEntityCode, + string $attributeCode, + string $attributeOptionCode, + array $data = [] + ): PromiseInterface|Promise { + return $this->resourceClient->upsertAsyncResource( + static::REFERENCE_ENTITY_ATTRIBUTE_OPTION_URI, + [$referenceEntityCode, $attributeCode, $attributeOptionCode], + $data + ); + } } diff --git a/src/Api/ReferenceEntityAttributeOptionApiInterface.php b/src/Api/ReferenceEntityAttributeOptionApiInterface.php index 1b1c5f8..730b03c 100644 --- a/src/Api/ReferenceEntityAttributeOptionApiInterface.php +++ b/src/Api/ReferenceEntityAttributeOptionApiInterface.php @@ -5,6 +5,8 @@ namespace Akeneo\Pim\ApiClient\Api; use Akeneo\Pim\ApiClient\Exception\HttpException; +use GuzzleHttp\Promise\PromiseInterface; +use Http\Promise\Promise; /** * @author Laurent Petard @@ -52,4 +54,23 @@ public function all(string $referenceEntityCode, string $attributeCode): array; * Status code 204 indicating that the reference entity attribute option has been well updated. */ public function upsert(string $referenceEntityCode, string $attributeCode, string $attributeOptionCode, array $data = []): int; + + /** + * Creates a reference entity attribute option if it does not exist yet, otherwise updates partially the attribute option. + * + * @param string $referenceEntityCode Code of the reference entity + * @param string $attributeCode Code of the attribute + * @param string $attributeOptionCode Code of the attribute option + * @param array $data Data of the attribute option to create or update + * + * @throws HttpException If the request failed. + * + * @return Promise + */ + public function upsertAsync( + string $referenceEntityCode, + string $attributeCode, + string $attributeOptionCode, + array $data = [] + ): PromiseInterface|Promise; } diff --git a/src/Api/ReferenceEntityRecordApi.php b/src/Api/ReferenceEntityRecordApi.php index 9571296..ad015a0 100644 --- a/src/Api/ReferenceEntityRecordApi.php +++ b/src/Api/ReferenceEntityRecordApi.php @@ -8,6 +8,8 @@ use Akeneo\Pim\ApiClient\Pagination\PageFactoryInterface; use Akeneo\Pim\ApiClient\Pagination\ResourceCursorFactoryInterface; use Akeneo\Pim\ApiClient\Pagination\ResourceCursorInterface; +use GuzzleHttp\Promise\PromiseInterface; +use Http\Promise\Promise; /** * @author Laurent Petard @@ -67,4 +69,14 @@ public function upsertList(string $referenceEntityCode, array $records): array { return $this->resourceClient->upsertJsonResourceList(static::REFERENCE_ENTITY_RECORDS_URI, [$referenceEntityCode], $records); } + + public function upsertAsync(string $referenceEntityCode, string $recordCode, array $data = []): PromiseInterface|Promise + { + return $this->resourceClient->upsertAsyncResource(static::REFERENCE_ENTITY_RECORD_URI, [$referenceEntityCode, $recordCode], $data); + } + + public function upsertAsyncList(string $referenceEntityCode, array $records): PromiseInterface|Promise + { + return $this->resourceClient->upsertAsyncJsonResourceList(static::REFERENCE_ENTITY_RECORDS_URI, [$referenceEntityCode], $records); + } } diff --git a/src/Api/ReferenceEntityRecordApiInterface.php b/src/Api/ReferenceEntityRecordApiInterface.php index f516050..1e2265e 100644 --- a/src/Api/ReferenceEntityRecordApiInterface.php +++ b/src/Api/ReferenceEntityRecordApiInterface.php @@ -6,6 +6,8 @@ use Akeneo\Pim\ApiClient\Exception\HttpException; use Akeneo\Pim\ApiClient\Pagination\ResourceCursorInterface; +use GuzzleHttp\Promise\PromiseInterface; +use Http\Promise\Promise; /** * API to mange the reference entity records. @@ -54,6 +56,19 @@ public function all(string $referenceEntityCode, array $queryParameters = []): R */ public function upsert(string $referenceEntityCode, string $recordCode, array $data = []): int; + /** + * Creates a reference entity record if it does not exist yet, otherwise updates partially the record. + * + * @param string $referenceEntityCode Code of the reference entity + * @param string $recordCode Code of the record + * @param array $data Data of the record to create or update + * + * @throws HttpException If the request failed. + * + * @return Promise + */ + public function upsertAsync(string $referenceEntityCode, string $recordCode, array $data = []): PromiseInterface|Promise; + /** * Updates or creates several reference entity records. * @@ -65,4 +80,16 @@ public function upsert(string $referenceEntityCode, string $recordCode, array $d * @return array returns the list of the responses of each created or updated record. */ public function upsertList(string $referenceEntityCode, array $records): array; + + /** + * Updates or creates several reference entity records. + * + * @param string $referenceEntityCode Code of the reference entity + * @param array $records Array containing the records to create or update + * + * @throws HttpException + * + * @return Promise + */ + public function upsertAsyncList(string $referenceEntityCode, array $records): PromiseInterface|Promise; } diff --git a/src/Client/AuthenticatedHttpClient.php b/src/Client/AuthenticatedHttpClient.php index 1232e64..6e93cec 100644 --- a/src/Client/AuthenticatedHttpClient.php +++ b/src/Client/AuthenticatedHttpClient.php @@ -6,6 +6,8 @@ use Akeneo\Pim\ApiClient\Exception\UnauthorizedHttpException; use Akeneo\Pim\ApiClient\Exception\UnprocessableEntityHttpException; use Akeneo\Pim\ApiClient\Security\Authentication; +use GuzzleHttp\Promise\PromiseInterface; +use Http\Promise\Promise; use Psr\Http\Message\ResponseInterface; /** @@ -76,4 +78,38 @@ private function renewTokens(UnauthorizedHttpException $unauthorizedHttpExceptio throw $unauthorizedHttpException; } } + + public function sendAsync( + string $httpMethod, + $uri, + array $headers = [], + $body = null + ): PromiseInterface|Promise { + if (null === $this->authentication->getAccessToken()) { + $tokens = $this->authenticationApi->authenticateByPassword( + $this->authentication->getClientId(), + $this->authentication->getSecret(), + $this->authentication->getUsername(), + $this->authentication->getPassword() + ); + + $this->authentication + ->setAccessToken($tokens['access_token']) + ->setRefreshToken($tokens['refresh_token']); + } + + try { + $headers['Authorization'] = sprintf('Bearer %s', $this->authentication->getAccessToken()); + return $this->basicHttpClient->sendAsync($httpMethod, $uri, $headers, $body); + } catch (UnauthorizedHttpException $e) { + $tokens = $this->renewTokens($e); + + $this->authentication + ->setAccessToken($tokens['access_token']) + ->setRefreshToken($tokens['refresh_token']); + + $headers['Authorization'] = sprintf('Bearer %s', $this->authentication->getAccessToken()); + return $this->basicHttpClient->sendAsync($httpMethod, $uri, $headers, $body); + } + } } diff --git a/src/Client/CachedResourceClient.php b/src/Client/CachedResourceClient.php index 906adab..a31f8d3 100644 --- a/src/Client/CachedResourceClient.php +++ b/src/Client/CachedResourceClient.php @@ -5,6 +5,8 @@ namespace Akeneo\Pim\ApiClient\Client; use Akeneo\Pim\ApiClient\Cache\CacheInterface; +use GuzzleHttp\Promise\PromiseInterface; +use Http\Promise\Promise; use Psr\Http\Message\ResponseInterface; /** @@ -73,6 +75,14 @@ public function upsertResource(string $uri, array $uriParameters = [], array $bo return $this->resourceClient->upsertResource($uri, $uriParameters, $body); } + public function upsertAsyncResource( + string $uri, + array $uriParameters = [], + array $body = [] + ): PromiseInterface|Promise { + return $this->resourceClient->upsertAsyncResource($uri, $uriParameters, $body); + } + /** * {@inheritdoc} */ @@ -81,6 +91,14 @@ public function upsertStreamResourceList(string $uri, array $uriParameters = [], return $this->resourceClient->upsertStreamResourceList($uri, $uriParameters, $resources); } + public function upsertAsyncStreamResourceList( + string $uri, + array $uriParameters = [], + $resources = [] + ): PromiseInterface|Promise { + return $this->resourceClient->upsertAsyncStreamResourceList($uri, $uriParameters, $resources); + } + /** * {@inheritdoc} */ @@ -89,6 +107,14 @@ public function upsertJsonResourceList(string $uri, array $uriParameters = [], a return $this->resourceClient->upsertJsonResourceList($uri, $uriParameters, $resources); } + public function upsertAsyncJsonResourceList( + string $uri, + array $uriParameters = [], + array $resources = [] + ): PromiseInterface|Promise { + return $this->resourceClient->upsertAsyncJsonResourceList($uri, $uriParameters, $resources); + } + /** * {@inheritdoc} */ @@ -120,4 +146,12 @@ public function upsertAndReturnResource(string $uri, array $uriParameters = [], { return $this->resourceClient->upsertAndReturnResource($uri, $uriParameters, $body); } + + public function upsertAsyncAndReturnPromise( + string $uri, + array $uriParameters = [], + array $body = [] + ): PromiseInterface|Promise { + return $this->resourceClient->upsertAsyncAndReturnPromise($uri, $uriParameters, $body); + } } diff --git a/src/Client/ClientInterface.php b/src/Client/ClientInterface.php new file mode 100644 index 0000000..173c927 --- /dev/null +++ b/src/Client/ClientInterface.php @@ -0,0 +1,15 @@ +httpExceptionHandler = new HttpExceptionHandler(); } - /** - * {@inheritdoc} - */ - public function sendRequest(string $httpMethod, $uri, array $headers = [], $body = null): ResponseInterface + private function prepareRequest(string $httpMethod, $uri, array $headers = [], $body = null): RequestInterface { $request = $this->requestFactory->createRequest($httpMethod, $uri); @@ -64,8 +63,29 @@ public function sendRequest(string $httpMethod, $uri, array $headers = [], $body } } + return $request; + } + + /** + * {@inheritdoc} + */ + public function sendRequest(string $httpMethod, $uri, array $headers = [], $body = null): ResponseInterface + { + $request = $this->prepareRequest($httpMethod, $uri, $headers, $body); + $response = $this->httpClient->sendRequest($request); return $this->httpExceptionHandler->transformResponseToException($request, $response); } + + public function sendAsync( + string $httpMethod, + $uri, + array $headers = [], + $body = null + ): PromiseInterface|Promise { + $request = $this->prepareRequest($httpMethod, $uri, $headers, $body); + + return $this->httpClient->sendAsyncRequest($request); + } } diff --git a/src/Client/HttpClientInterface.php b/src/Client/HttpClientInterface.php index c67761d..208a37b 100644 --- a/src/Client/HttpClientInterface.php +++ b/src/Client/HttpClientInterface.php @@ -3,6 +3,8 @@ namespace Akeneo\Pim\ApiClient\Client; use Akeneo\Pim\ApiClient\Exception\HttpException; +use GuzzleHttp\Promise\PromiseInterface; +use Http\Promise\Promise; use Psr\Http\Message\ResponseInterface; use Psr\Http\Message\StreamInterface; use Psr\Http\Message\UriInterface; @@ -29,4 +31,23 @@ interface HttpClientInterface * @return ResponseInterface */ public function sendRequest(string $httpMethod, $uri, array $headers = [], $body = null): ResponseInterface; + + /** + * Sends a request. + * + * @param string $httpMethod HTTP method to use + * @param string|UriInterface $uri URI of the request + * @param array $headers headers of the request + * @param string|StreamInterface|null $body body of the request + * + * @throws HttpException If the request failed. + * + * @return PromiseInterface|Promise + */ + public function sendAsync( + string $httpMethod, + $uri, + array $headers = [], + $body = null + ): PromiseInterface|Promise; } diff --git a/src/Client/ResourceClient.php b/src/Client/ResourceClient.php index 7d56f53..c265ac3 100644 --- a/src/Client/ResourceClient.php +++ b/src/Client/ResourceClient.php @@ -9,6 +9,8 @@ use Akeneo\Pim\ApiClient\Routing\UriGeneratorInterface; use Akeneo\Pim\ApiClient\Stream\MultipartStreamBuilderFactory; use Akeneo\Pim\ApiClient\Stream\UpsertResourceListResponseFactory; +use GuzzleHttp\Promise\PromiseInterface; +use Http\Promise\Promise; use Psr\Http\Message\ResponseInterface; use Psr\Http\Message\StreamInterface; @@ -124,6 +126,14 @@ public function upsertResource(string $uri, array $uriParameters = [], array $bo return $response->getStatusCode(); } + public function upsertAsyncResource( + string $uri, + array $uriParameters = [], + array $body = [] + ): PromiseInterface|Promise { + return $this->sendAsyncUpsertRequest($uri, $uriParameters, $body); + } + /** * {@inheritdoc} */ @@ -134,10 +144,15 @@ public function upsertAndReturnResource(string $uri, array $uriParameters = [], return json_decode($response->getBody()->getContents(), true); } - /** - * {@inheritdoc} - */ - public function upsertStreamResourceList(string $uri, array $uriParameters = [], $resources = []): \Traversable + public function upsertAsyncAndReturnPromise( + string $uri, + array $uriParameters = [], + array $body = [] + ): PromiseInterface|Promise { + return $this->sendAsyncUpsertRequest($uri, $uriParameters, $body); + } + + public function prepareResourceListRequest($resources = []): StreamInterface|string { if (!is_array($resources) && !$resources instanceof StreamInterface) { throw new InvalidArgumentException('The parameter "resources" must be an array or an instance of StreamInterface.'); @@ -158,6 +173,15 @@ public function upsertStreamResourceList(string $uri, array $uriParameters = [], $body = $resources; } + return $body; + } + + /** + * {@inheritdoc} + */ + public function upsertStreamResourceList(string $uri, array $uriParameters = [], $resources = []): \Traversable + { + $body = $this->prepareResourceListRequest($resources); $uri = $this->uriGenerator->generate($uri, $uriParameters); $response = $this->httpClient->sendRequest( 'PATCH', @@ -169,6 +193,21 @@ public function upsertStreamResourceList(string $uri, array $uriParameters = [], return $this->upsertListResponseFactory->create($response->getBody()); } + public function upsertAsyncStreamResourceList( + string $uri, + array $uriParameters = [], + $resources = [] + ): PromiseInterface|Promise { + $body = $this->prepareResourceListRequest($resources); + $uri = $this->uriGenerator->generate($uri, $uriParameters); + return $this->httpClient->sendAsync( + 'PATCH', + $uri, + ['Content-Type' => 'application/vnd.akeneo.collection+json'], + $body + ); + } + /** * {@inheritdoc} */ @@ -190,6 +229,20 @@ public function upsertJsonResourceList(string $uri, array $uriParameters = [], a return $response; } + public function upsertAsyncJsonResourceList( + string $uri, + array $uriParameters = [], + array $resources = [] + ): PromiseInterface|Promise { + $uri = $this->uriGenerator->generate($uri, $uriParameters); + return $this->httpClient->sendAsync( + 'PATCH', + $uri, + ['Content-Type' => 'application/json'], + json_encode($resources) + ); + } + /** * {@inheritdoc} */ @@ -239,4 +292,21 @@ private function sendUpsertRequest(string $uri, array $uriParameters = [], array json_encode($body) ); } + + private function sendAsyncUpsertRequest( + string $uri, + array $uriParameters = [], + array $body = [] + ): PromiseInterface|Promise { + unset($body['_links']); + + $uri = $this->uriGenerator->generate($uri, $uriParameters); + + return $this->httpClient->sendAsync( + 'PATCH', + $uri, + ['Content-Type' => 'application/json'], + json_encode($body) + ); + } } diff --git a/src/Client/ResourceClientInterface.php b/src/Client/ResourceClientInterface.php index 4cdd408..a66d709 100644 --- a/src/Client/ResourceClientInterface.php +++ b/src/Client/ResourceClientInterface.php @@ -6,6 +6,8 @@ use Akeneo\Pim\ApiClient\Exception\HttpException; use Akeneo\Pim\ApiClient\Exception\InvalidArgumentException; +use GuzzleHttp\Promise\PromiseInterface; +use Http\Promise\Promise; use Psr\Http\Message\ResponseInterface; use Psr\Http\Message\StreamInterface; @@ -109,6 +111,23 @@ public function createMultipartResource(string $uri, array $uriParameters = [], */ public function upsertResource(string $uri, array $uriParameters = [], array $body = []): int; + /** + * Creates a resource if it does not exist yet, otherwise updates partially the resource. + * + * @param string $uri URI of the resource + * @param array $uriParameters URI parameters of the resource + * @param array $body Body of the request + * + * @throws HttpException If the request failed. + * + * @return PromiseInterface|Promise + */ + public function upsertAsyncResource( + string $uri, + array $uriParameters = [], + array $body = [] + ); + /** * Creates and returns a resource if it does not exist yet, otherwise updates partially and returns the resource. * @@ -121,6 +140,22 @@ public function upsertResource(string $uri, array $uriParameters = [], array $bo */ public function upsertAndReturnResource(string $uri, array $uriParameters = [], array $body = []): array; + /** + * Creates and returns a resource if it does not exist yet, otherwise updates partially and returns the resource. + * + * @param string $uri URI of the resource + * @param array $uriParameters URI parameters of the resource + * @param array $body Body of the request + * + * @throws HttpException If the request failed. + * + */ + public function upsertAsyncAndReturnPromise( + string $uri, + array $uriParameters = [], + array $body = [] + ); + /** * Updates or creates several resources using a stream for the request and the response. * @@ -136,6 +171,25 @@ public function upsertAndReturnResource(string $uri, array $uriParameters = [], */ public function upsertStreamResourceList(string $uri, array $uriParameters = [], $resources = []): \Traversable; + /** + * Updates or creates several resources using a stream for the request and the response. + * + * @param string $uri URI of the resource + * @param array $uriParameters URI parameters of the resource + * @param array|StreamInterface $resources array of resources to create or update. + * You can pass your own StreamInterface implementation as well. + * + * @throws HttpException If the request failed. + * @throws InvalidArgumentException If the resources or any part thereof are invalid. + * + * @return PromiseInterface|Promise returns a Promise + */ + public function upsertAsyncStreamResourceList( + string $uri, + array $uriParameters = [], + $resources = [] + ); + /** * Updates or creates several resources using a single JSON string for the request and the response. * @@ -150,6 +204,24 @@ public function upsertStreamResourceList(string $uri, array $uriParameters = [], */ public function upsertJsonResourceList(string $uri, array $uriParameters = [], array $resources = []): array; + /** + * Updates or creates several resources using a single JSON string for the request and the response. + * + * @param string $uri URI of the resource + * @param array $uriParameters URI parameters of the resource + * @param array $resources array of resources to create or update. + * + * @throws HttpException If the request failed. + * @throws InvalidArgumentException If the resources or any part thereof are invalid. + * + * @return PromiseInterface|Promise + */ + public function upsertAsyncJsonResourceList( + string $uri, + array $uriParameters = [], + array $resources = [] + ); + /** * Deletes a resource. * diff --git a/tests/Api/AppCatalog/UpsertAppCatalogIntegration.php b/tests/Api/AppCatalog/UpsertAppCatalogIntegration.php index 15c2052..bed0c01 100644 --- a/tests/Api/AppCatalog/UpsertAppCatalogIntegration.php +++ b/tests/Api/AppCatalog/UpsertAppCatalogIntegration.php @@ -10,6 +10,7 @@ use donatj\MockWebServer\RequestInfo; use donatj\MockWebServer\Response; use donatj\MockWebServer\ResponseStack; +use Http\Promise\Promise; use PHPUnit\Framework\Assert; /** @@ -42,4 +43,32 @@ public function test_upsert_catalog() Assert::assertSame(json_decode($expectedJson, true), $response); } + + public function test_upsert_async_catalog() + { + $catalogId = '12351d98-200e-4bbc-aa19-7fdda1bd14f2'; + $catalogData = ['name' => 'A catalog name']; + $expectedJson = <<server->setResponseOfPath( + '/' . sprintf(AppCatalogApi::APP_CATALOG_URI, $catalogId), + new ResponseStack( + new Response($expectedJson, [], HttpClient::HTTP_OK) + ) + ); + + $api = $this->createClientByPassword()->getAppCatalogApi(); + $promise = $api->upsertAsync($catalogId, $catalogData); + Assert::assertInstanceOf(Promise::class, $promise); + + $response = json_decode($promise->wait()->getBody()->getContents(), true); + + Assert::assertSame(json_decode($expectedJson, true), $response); + } } diff --git a/tests/Api/Asset/UpsertAssetIntegration.php b/tests/Api/Asset/UpsertAssetIntegration.php index d39a80f..ca56521 100644 --- a/tests/Api/Asset/UpsertAssetIntegration.php +++ b/tests/Api/Asset/UpsertAssetIntegration.php @@ -9,6 +9,7 @@ use donatj\MockWebServer\RequestInfo; use donatj\MockWebServer\Response; use donatj\MockWebServer\ResponseStack; +use Http\Promise\Promise; use PHPUnit\Framework\Assert; class UpsertAssetIntegration extends ApiTestCase @@ -48,4 +49,43 @@ public function test_upsert_asset() Assert::assertSame($this->server->getLastRequest()->jsonSerialize()[RequestInfo::JSON_KEY_INPUT], json_encode($asset)); Assert::assertSame(204, $response); } + + public function test_upsert_async_asset() + { + $this->server->setResponseOfPath( + '/' . sprintf(AssetApi::ASSET_URI, 'packshot', 'sku_54628_telescope'), + new ResponseStack( + new Response('', [], 204) + ) + ); + + $asset = [ + "code" => "sku_54628_telescope", + "values" => [ + "media_preview" => [ + [ + "locale" => null, + "channel" => null, + "data" => "sku_54628_picture1.jpg" + ] + ], + "photographer" => [ + [ + "locale" => null, + "channel" => null, + "data" => "ben_levy" + ] + ] + ] + ]; + + $api = $this->createClientByPassword()->getAssetManagerApi(); + $promise = $api->upsertAsync('packshot', 'sku_54628_telescope', $asset); + Assert::assertInstanceOf(Promise::class, $promise); + + $response = $promise->wait(); + + Assert::assertSame($this->server->getLastRequest()->jsonSerialize()[RequestInfo::JSON_KEY_INPUT], json_encode($asset)); + Assert::assertSame(204, $response->getStatusCode()); + } } diff --git a/tests/Api/Asset/UpsertListAssetIntegration.php b/tests/Api/Asset/UpsertListAssetIntegration.php index 9ff1737..22ab2d2 100644 --- a/tests/Api/Asset/UpsertListAssetIntegration.php +++ b/tests/Api/Asset/UpsertListAssetIntegration.php @@ -5,10 +5,12 @@ namespace Akeneo\Pim\ApiClient\tests\Api\Asset; use Akeneo\Pim\ApiClient\Api\AssetManager\AssetApi; +use Akeneo\Pim\ApiClient\Stream\UpsertResourceListResponseFactory; use Akeneo\Pim\ApiClient\tests\Api\ApiTestCase; use donatj\MockWebServer\RequestInfo; use donatj\MockWebServer\Response; use donatj\MockWebServer\ResponseStack; +use Http\Promise\Promise; use PHPUnit\Framework\Assert; class UpsertListAssetIntegration extends ApiTestCase @@ -93,4 +95,89 @@ public function test_upsert_a_list_of_assets() Assert::assertSame($this->server->getLastRequest()->jsonSerialize()[RequestInfo::JSON_KEY_INPUT], json_encode($assets)); Assert::assertSame($expectedResponses, $responses); } + + public function test_upsert_async_a_list_of_assets() + { + $responseBody = <<server->setResponseOfPath( + '/' . sprintf(AssetApi::ASSETS_URI, 'packshot'), + new ResponseStack( + new Response($responseBody, [], 200) + ) + ); + + $assets = [ + [ + "code" => "sku_54628_telescope", + "values" => [ + "media_preview" => [ + [ + "locale" => null, + "channel" => null, + "data" => "sku_54628_picture1.jpg" + ] + ], + "photographer" => [ + [ + "locale" => null, + "channel" => null, + "data" => "ben_levy" + ] + ] + ] + ], + [ + "code" => "sku_45689_dobson", + "values" => [ + "media_preview" => [ + [ + "locale" => null, + "channel" => null, + "data" => "sku_45689_dobson_pic1.jpg" + ] + ], + "photographer" => [ + [ + "locale" => null, + "channel" => null, + "data" => "ben_levy" + ] + ] + ] + ] + ]; + + $expectedResponses = [ + [ + 'code' => 'sku_54628_telescope', + 'status_code' => 204 + ], + [ + 'code' => 'sku_45689_dobson', + 'status_code' => 201 + ], + ]; + + $api = $this->createClientByPassword()->getAssetManagerApi(); + $promise = $api->upsertAsyncList('packshot', $assets); + + Assert::assertInstanceOf(Promise::class, $promise); + + $responses = json_decode($promise->wait()->getBody()->getContents(), true); + + Assert::assertSame($this->server->getLastRequest()->jsonSerialize()[RequestInfo::JSON_KEY_INPUT], json_encode($assets)); + Assert::assertSame($expectedResponses, $responses); + } } diff --git a/tests/Api/AssetAttribute/UpsertAssetFamilyAttributeIntegration.php b/tests/Api/AssetAttribute/UpsertAssetFamilyAttributeIntegration.php index b4b05b0..db1e394 100644 --- a/tests/Api/AssetAttribute/UpsertAssetFamilyAttributeIntegration.php +++ b/tests/Api/AssetAttribute/UpsertAssetFamilyAttributeIntegration.php @@ -9,6 +9,7 @@ use donatj\MockWebServer\RequestInfo; use donatj\MockWebServer\Response; use donatj\MockWebServer\ResponseStack; +use Http\Promise\Promise; use PHPUnit\Framework\Assert; class UpsertAssetFamilyAttributeIntegration extends ApiTestCase @@ -45,4 +46,40 @@ public function test_upsert_asset_family_attribute() ); Assert::assertSame(204, $response); } + + public function test_upsert_async_asset_family_attribute() + { + $this->server->setResponseOfPath( + '/' . sprintf(AssetAttributeApi::ASSET_ATTRIBUTE_URI, 'packshot', 'media_preview'), + new ResponseStack( + new Response('', [], 204) + ) + ); + + $assetFamilyAttribute = [ + 'code' => 'media_preview', + 'labels' => [ + 'en_US' => 'Media Preview' + ], + 'type' => 'media_link', + "value_per_locale" => false, + "value_per_channel" => false, + "is_required_for_completeness" => false, + "prefix" => "dam.com/my_assets/", + "suffix" => null, + "media_type" => "image" + ]; + + $api = $this->createClientByPassword()->getAssetAttributeApi(); + $promise = $api->upsertAsync('packshot', 'media_preview', $assetFamilyAttribute); + Assert::assertInstanceOf(Promise::class, $promise); + + $response = $promise->wait(); + + Assert::assertSame( + $this->server->getLastRequest()->jsonSerialize()[RequestInfo::JSON_KEY_INPUT], + json_encode($assetFamilyAttribute) + ); + Assert::assertSame(204, $response->getStatusCode()); + } } diff --git a/tests/Api/AssetAttributeOption/UpsertAssetFamilyAttributeOptionIntegration.php b/tests/Api/AssetAttributeOption/UpsertAssetFamilyAttributeOptionIntegration.php index d6364af..e37fe43 100644 --- a/tests/Api/AssetAttributeOption/UpsertAssetFamilyAttributeOptionIntegration.php +++ b/tests/Api/AssetAttributeOption/UpsertAssetFamilyAttributeOptionIntegration.php @@ -9,6 +9,7 @@ use donatj\MockWebServer\RequestInfo; use donatj\MockWebServer\Response; use donatj\MockWebServer\ResponseStack; +use Http\Promise\Promise; use PHPUnit\Framework\Assert; class UpsertAssetFamilyAttributeOptionIntegration extends ApiTestCase @@ -44,4 +45,39 @@ public function test_upsert_asset_family_attribute_option() ); Assert::assertSame(204, $response); } + + public function test_upsert_async_asset_family_attribute_option() + { + $this->server->setResponseOfPath( + '/' . sprintf( + AssetAttributeOptionApi::ASSET_ATTRIBUTE_OPTION_URI, + 'packshot', + 'wearing_model_size', + 'size_27' + ), + new ResponseStack( + new Response('', [], 204) + ) + ); + + $assetFamilyAttributeOption = [ + "code" => "size_27", + "labels" => [ + "en_US" => "Size 27", + "fr_FR" => "Taille 36" + ] + ]; + + $api = $this->createClientByPassword()->getAssetAttributeOptionApi(); + $promise = $api->upsertAsync('packshot', 'wearing_model_size', 'size_27', $assetFamilyAttributeOption); + Assert::assertInstanceOf(Promise::class, $promise); + + $response = $promise->wait(); + + Assert::assertSame( + $this->server->getLastRequest()->jsonSerialize()[RequestInfo::JSON_KEY_INPUT], + json_encode($assetFamilyAttributeOption) + ); + Assert::assertSame(204, $response->getStatusCode()); + } } diff --git a/tests/Api/AssetFamily/UpsertAssetFamilyIntegration.php b/tests/Api/AssetFamily/UpsertAssetFamilyIntegration.php index 7104351..2e7d598 100644 --- a/tests/Api/AssetFamily/UpsertAssetFamilyIntegration.php +++ b/tests/Api/AssetFamily/UpsertAssetFamilyIntegration.php @@ -7,6 +7,7 @@ use donatj\MockWebServer\RequestInfo; use donatj\MockWebServer\Response; use donatj\MockWebServer\ResponseStack; +use Http\Promise\Promise; use PHPUnit\Framework\Assert; class UpsertAssetFamilyIntegration extends ApiTestCase @@ -33,4 +34,30 @@ public function test_upsert_asset_family() Assert::assertSame($this->server->getLastRequest()->jsonSerialize()[RequestInfo::JSON_KEY_INPUT], json_encode($assetFamily)); Assert::assertSame(201, $response); } + + public function test_upsert_async_asset_family() + { + $this->server->setResponseOfPath( + '/' . sprintf(AssetFamilyApi::ASSET_FAMILY_URI, 'packshot'), + new ResponseStack( + new Response('', [], 201) + ) + ); + + $assetFamily = [ + 'code' => 'packshot', + 'labels' => [ + 'en_US' => 'Packshots' + ] + ]; + + $api = $this->createClientByPassword()->getAssetFamilyApi(); + $promise = $api->upsertAsync('packshot', $assetFamily); + Assert::assertInstanceOf(Promise::class, $promise); + + $response = $promise->wait(); + + Assert::assertSame($this->server->getLastRequest()->jsonSerialize()[RequestInfo::JSON_KEY_INPUT], json_encode($assetFamily)); + Assert::assertSame(201, $response->getStatusCode()); + } } diff --git a/tests/Api/AssetReferenceFile/DownloadAssetReferenceFileIntegration.php b/tests/Api/AssetReferenceFile/DownloadAssetReferenceFileIntegration.php index 5e01783..3b0e657 100644 --- a/tests/Api/AssetReferenceFile/DownloadAssetReferenceFileIntegration.php +++ b/tests/Api/AssetReferenceFile/DownloadAssetReferenceFileIntegration.php @@ -3,6 +3,7 @@ namespace Akeneo\Pim\ApiClient\tests\Api\AssetReferenceFile; use Akeneo\Pim\ApiClient\Api\AssetReferenceFileApi; +use Akeneo\Pim\ApiClient\Exception\NotFoundHttpException; use Akeneo\Pim\ApiClient\tests\Api\ApiTestCase; use donatj\MockWebServer\RequestInfo; use donatj\MockWebServer\Response; @@ -56,11 +57,9 @@ public function test_download_a_not_localizable_asset_reference_file() Assert::assertSame(file_get_contents($expectedFilePath), $downloadResponse->getBody()->getContents()); } - /** - * @expectedException \Akeneo\Pim\ApiClient\Exception\NotFoundHttpException - */ public function test_download_from_localizable_asset_not_found() { + self::expectException(NotFoundHttpException::class); $this->server->setResponseOfPath( '/' . sprintf(AssetReferenceFileApi::ASSET_REFERENCE_FILE_DOWNLOAD_URI, 'ziggy', 'en_US'), new ResponseStack( @@ -72,11 +71,9 @@ public function test_download_from_localizable_asset_not_found() $api->downloadFromLocalizableAsset('ziggy', 'en_US'); } - /** - * @expectedException \Akeneo\Pim\ApiClient\Exception\NotFoundHttpException - */ public function test_download_from_not_localizable_asset_not_found() { + self::expectException(NotFoundHttpException::class); $this->server->setResponseOfPath( '/' . sprintf( AssetReferenceFileApi::ASSET_REFERENCE_FILE_DOWNLOAD_URI, diff --git a/tests/Api/AssetReferenceFile/UploadAssetReferenceFileIntegration.php b/tests/Api/AssetReferenceFile/UploadAssetReferenceFileIntegration.php index a07b2c5..e9f206e 100644 --- a/tests/Api/AssetReferenceFile/UploadAssetReferenceFileIntegration.php +++ b/tests/Api/AssetReferenceFile/UploadAssetReferenceFileIntegration.php @@ -3,6 +3,8 @@ namespace Akeneo\Pim\ApiClient\tests\v2_1\Api\AssetReferenceFile; use Akeneo\Pim\ApiClient\Api\AssetReferenceFileApi; +use Akeneo\Pim\ApiClient\Exception\NotFoundHttpException; +use Akeneo\Pim\ApiClient\Exception\UploadAssetReferenceFileErrorException; use Akeneo\Pim\ApiClient\tests\Api\ApiTestCase; use donatj\MockWebServer\RequestInfo; use donatj\MockWebServer\Response; @@ -106,11 +108,10 @@ public function test_upload_from_resource_file() Assert::assertEquals($this->fakeUploadLocalizableInformations(), $assetReferenceFile); } - /** - * @expectedException \Akeneo\Pim\ApiClient\Exception\NotFoundHttpException - */ public function test_upload_for_an_unknown_asset() { + self::expectException(NotFoundHttpException::class); + $filePath = realpath(__DIR__ . '/../../fixtures/ziggy.png'); $this->server->setResponseOfPath( @@ -125,11 +126,10 @@ public function test_upload_for_an_unknown_asset() $api->uploadForLocalizableAsset($filePath, 'unknown_asset', 'en_US'); } - /** - * @expectedException \Akeneo\Pim\ApiClient\Exception\UploadAssetReferenceFileErrorException - */ public function test_upload_a_file_that_cannot_be_transformed_for_the_variations() { + self::expectException(UploadAssetReferenceFileErrorException::class); + $filePath = realpath(__DIR__ . '/../../fixtures/unicorn.png'); $this->server->setResponseOfPath( diff --git a/tests/Api/AssetVariationFile/DownloadAssetVariationFileApiIntegration.php b/tests/Api/AssetVariationFile/DownloadAssetVariationFileApiIntegration.php index 26561a9..d0990b5 100644 --- a/tests/Api/AssetVariationFile/DownloadAssetVariationFileApiIntegration.php +++ b/tests/Api/AssetVariationFile/DownloadAssetVariationFileApiIntegration.php @@ -3,6 +3,7 @@ namespace Akeneo\Pim\ApiClient\tests\v2_1\Api\AssetVariationFile; use Akeneo\Pim\ApiClient\Api\AssetVariationFileApi; +use Akeneo\Pim\ApiClient\Exception\NotFoundHttpException; use Akeneo\Pim\ApiClient\tests\Api\ApiTestCase; use donatj\MockWebServer\RequestInfo; use donatj\MockWebServer\Response; @@ -58,11 +59,10 @@ public function test_download_a_not_localizable_asset_variation_file() Assert::assertSame(file_get_contents($expectedFilePath), $downloadResponse->getBody()->getContents()); } - /** - * @expectedException \Akeneo\Pim\ApiClient\Exception\NotFoundHttpException - */ public function test_download_from_localizable_asset_not_found() { + self::expectException(NotFoundHttpException::class); + $this->server->setResponseOfPath( '/' . sprintf(AssetVariationFileApi::ASSET_VARIATION_FILE_DOWNLOAD_URI, 'ziggy', 'mobile', 'en_US'), new ResponseStack( @@ -74,11 +74,10 @@ public function test_download_from_localizable_asset_not_found() $api->downloadFromLocalizableAsset('ziggy', 'mobile', 'en_US'); } - /** - * @expectedException \Akeneo\Pim\ApiClient\Exception\NotFoundHttpException - */ public function test_download_from_not_localizable_asset_not_found() { + self::expectException(NotFoundHttpException::class); + $this->server->setResponseOfPath( '/' . sprintf( AssetVariationFileApi::ASSET_VARIATION_FILE_DOWNLOAD_URI, diff --git a/tests/Api/AssetVariationFile/UploadAssetVariationFileApiIntegration.php b/tests/Api/AssetVariationFile/UploadAssetVariationFileApiIntegration.php index 58a0502..7082fd0 100644 --- a/tests/Api/AssetVariationFile/UploadAssetVariationFileApiIntegration.php +++ b/tests/Api/AssetVariationFile/UploadAssetVariationFileApiIntegration.php @@ -3,6 +3,8 @@ namespace Akeneo\Pim\ApiClient\tests\v2_1\Api\AssetVariationFile; use Akeneo\Pim\ApiClient\Api\AssetVariationFileApi; +use Akeneo\Pim\ApiClient\Exception\NotFoundHttpException; +use Akeneo\Pim\ApiClient\Exception\UnprocessableEntityHttpException; use Akeneo\Pim\ApiClient\tests\Api\ApiTestCase; use donatj\MockWebServer\RequestInfo; use donatj\MockWebServer\Response; @@ -108,11 +110,10 @@ public function test_upload_from_resource_file() Assert::assertEquals($this->fakeUploadLocalizableInformations(), $assetReferenceFile); } - /** - * @expectedException \Akeneo\Pim\ApiClient\Exception\NotFoundHttpException - */ public function test_upload_for_an_unknown_asset() { + self::expectException(NotFoundHttpException::class); + $filePath = realpath(__DIR__ . '/../../fixtures/ziggy.png'); $this->server->setResponseOfPath( @@ -127,11 +128,9 @@ public function test_upload_for_an_unknown_asset() $api->uploadForLocalizableAsset($filePath, 'unknown_asset', 'ecommerce', 'en_US'); } - /** - * @expectedException \Akeneo\Pim\ApiClient\Exception\UnprocessableEntityHttpException - */ public function test_upload_for_an_asset_that_should_be_localizable() { + self::expectException(UnprocessableEntityHttpException::class); $filePath = realpath(__DIR__ . '/../../fixtures/unicorn.png'); $this->server->setResponseOfPath( diff --git a/tests/Api/ProductUuid/UpsertListProductUuidIntegration.php b/tests/Api/ProductUuid/UpsertListProductUuidIntegration.php index 20870cd..86efabf 100644 --- a/tests/Api/ProductUuid/UpsertListProductUuidIntegration.php +++ b/tests/Api/ProductUuid/UpsertListProductUuidIntegration.php @@ -4,11 +4,13 @@ use Akeneo\Pim\ApiClient\Api\ProductUuidApi; use Akeneo\Pim\ApiClient\Client\HttpClient; +use Akeneo\Pim\ApiClient\Stream\UpsertResourceListResponseFactory; use Akeneo\Pim\ApiClient\tests\Api\ApiTestCase; use donatj\MockWebServer\RequestInfo; use donatj\MockWebServer\Response; use donatj\MockWebServer\ResponseStack; use Http\Discovery\Psr17FactoryDiscovery; +use Http\Promise\Promise; use PHPUnit\Framework\Assert; /** @@ -56,6 +58,39 @@ public function test_upsert_list() ], $responseLines[2]); } + public function test_upsert_async_list() + { + $upsertListResponseFactory = new UpsertResourceListResponseFactory(); + $api = $this->createClientByPassword()->getProductUuidApi(); + $promise = $api->upsertAsyncList($this->getProductToUpsert()); + + Assert::assertInstanceOf(Promise::class, $promise); + + $response = $upsertListResponseFactory->create($promise->wait()->getBody()); + + Assert::assertSame( + $this->server->getLastRequest()->jsonSerialize()[RequestInfo::JSON_KEY_INPUT], + $this->getProductToUpsertJson() + ); + + Assert::assertInstanceOf('\Iterator', $response); + + $responseLines = iterator_to_array($response); + Assert::assertCount(2, $responseLines); + + Assert::assertSame([ + 'line' => 1, + 'uuid' => '12951d98-210e-4bRC-ab18-7fdgf1bd14f3', + 'status_code' => HttpClient::HTTP_NO_CONTENT, + ], $responseLines[1]); + + Assert::assertSame([ + 'line' => 2, + 'uuid' => '12951d98-210e-4bRC-ab18-7fdgf1bd14f4', + 'status_code' => HttpClient::HTTP_CREATED, + ], $responseLines[2]); + } + public function test_upsert_list_from_stream() { $resources = fopen('php://memory', 'w+'); @@ -89,6 +124,44 @@ public function test_upsert_list_from_stream() ], $responseLines[2]); } + public function test_upsert_async_list_from_stream() + { + $upsertListResponseFactory = new UpsertResourceListResponseFactory(); + $resources = fopen('php://memory', 'w+'); + fwrite($resources, $this->getProductToUpsertJson()); + rewind($resources); + + $streamedResources = Psr17FactoryDiscovery::findStreamFactory()->createStreamFromResource($resources); + $api = $this->createClientByPassword()->getProductUuidApi(); + $promise = $api->upsertAsyncList($streamedResources); + + Assert::assertInstanceOf(Promise::class, $promise); + + $response = $upsertListResponseFactory->create($promise->wait()->getBody()); + + Assert::assertSame( + $this->server->getLastRequest()->jsonSerialize()[RequestInfo::JSON_KEY_INPUT], + $this->getProductToUpsertJson() + ); + + Assert::assertInstanceOf('\Iterator', $response); + + $responseLines = iterator_to_array($response); + Assert::assertCount(2, $responseLines); + + Assert::assertSame([ + 'line' => 1, + 'uuid' => '12951d98-210e-4bRC-ab18-7fdgf1bd14f3', + 'status_code' => HttpClient::HTTP_NO_CONTENT, + ], $responseLines[1]); + + Assert::assertSame([ + 'line' => 2, + 'uuid' => '12951d98-210e-4bRC-ab18-7fdgf1bd14f4', + 'status_code' => HttpClient::HTTP_CREATED, + ], $responseLines[2]); + } + private function getProductToUpsertJson(): string { return <<server->setResponseOfPath( + '/' . sprintf(ProductUuidApi::PRODUCT_UUID_URI, '12951d98-210e-4bRC-ab18-7fdgf1bd14f3'), + new ResponseStack( + new Response('', [], HttpClient::HTTP_NO_CONTENT) + ) + ); + + $api = $this->createClientByPassword()->getProductUuidApi(); + + $parameters = [ + 'identifier' => 'black_docks', + 'enabled' => false, + 'values' => [ + 'name' => [ + [ + 'locale' => 'en_US', + 'scope' => null, + 'data' => 'Black Docks', + ], + ], + ] + ]; + + $promise = $api->upsertAsync('12951d98-210e-4bRC-ab18-7fdgf1bd14f3', $parameters); + Assert::assertInstanceOf(Promise::class, $promise); + + $response = $promise->wait(); + + Assert::assertSame($this->server->getLastRequest()->jsonSerialize()[RequestInfo::JSON_KEY_INPUT], json_encode($parameters)); + + Assert::assertSame(HttpClient::HTTP_NO_CONTENT, $response->getStatusCode()); + } } diff --git a/tests/Api/ReferenceEntity/UpsertReferenceEntityIntegration.php b/tests/Api/ReferenceEntity/UpsertReferenceEntityIntegration.php index a9f96d3..92632e5 100644 --- a/tests/Api/ReferenceEntity/UpsertReferenceEntityIntegration.php +++ b/tests/Api/ReferenceEntity/UpsertReferenceEntityIntegration.php @@ -7,6 +7,7 @@ use donatj\MockWebServer\RequestInfo; use donatj\MockWebServer\Response; use donatj\MockWebServer\ResponseStack; +use Http\Promise\Promise; use PHPUnit\Framework\Assert; class UpsertReferenceEntityIntegration extends ApiTestCase @@ -33,4 +34,31 @@ public function test_upsert_reference_entity() Assert::assertSame($this->server->getLastRequest()->jsonSerialize()[RequestInfo::JSON_KEY_INPUT], json_encode($referenceEntity)); Assert::assertSame(204, $response); } + + public function test_upsert_async_reference_entity() + { + $this->server->setResponseOfPath( + '/' . sprintf(ReferenceEntityApi::REFERENCE_ENTITY_URI, 'brand'), + new ResponseStack( + new Response('', [], 204) + ) + ); + + $referenceEntity = [ + 'code' => 'brand', + 'labels' => [ + 'en_US' => 'Brand' + ] + ]; + + $api = $this->createClientByPassword()->getReferenceEntityApi(); + $promise = $api->upsertAsync('brand', $referenceEntity); + + Assert::assertInstanceOf(Promise::class, $promise); + + $response = $promise->wait(); + + Assert::assertSame($this->server->getLastRequest()->jsonSerialize()[RequestInfo::JSON_KEY_INPUT], json_encode($referenceEntity)); + Assert::assertSame(204, $response->getStatusCode()); + } } diff --git a/tests/Api/ReferenceEntityRecord/UpsertListReferenceEntityRecordIntegration.php b/tests/Api/ReferenceEntityRecord/UpsertListReferenceEntityRecordIntegration.php index 8f11902..861997b 100644 --- a/tests/Api/ReferenceEntityRecord/UpsertListReferenceEntityRecordIntegration.php +++ b/tests/Api/ReferenceEntityRecord/UpsertListReferenceEntityRecordIntegration.php @@ -3,10 +3,12 @@ namespace Akeneo\Pim\ApiClient\tests\Api\ReferenceEntityRecord; use Akeneo\Pim\ApiClient\Api\ReferenceEntityRecordApi; +use Akeneo\Pim\ApiClient\Stream\UpsertResourceListResponseFactory; use Akeneo\Pim\ApiClient\tests\Api\ApiTestCase; use donatj\MockWebServer\RequestInfo; use donatj\MockWebServer\Response; use donatj\MockWebServer\ResponseStack; +use Http\Promise\Promise; use PHPUnit\Framework\Assert; class UpsertListReferenceEntityRecordIntegration extends ApiTestCase @@ -77,4 +79,74 @@ public function test_upsert_a_list_of_reference_entity_records() Assert::assertSame($this->server->getLastRequest()->jsonSerialize()[RequestInfo::JSON_KEY_INPUT], json_encode($records)); Assert::assertSame($expectedResponses, $responses); } + + public function test_upsert_async_a_list_of_reference_entity_records() + { + $responseBody = <<server->setResponseOfPath( + '/' . sprintf(ReferenceEntityRecordApi::REFERENCE_ENTITY_RECORDS_URI, 'designer'), + new ResponseStack( + new Response($responseBody, [], 200) + ) + ); + + $records = [ + [ + 'code' => 'starck', + 'values' => [ + 'label' => [ + [ + 'channel' => null, + 'locale' => 'en_US', + 'data' => 'Philippe Starck' + ], + ] + ] + ], + [ + 'code' => 'dyson', + 'values' => [ + 'label' => [ + [ + 'channel' => null, + 'locale' => 'en_US', + 'data' => 'James Dyson' + ], + ] + ] + ] + ]; + + $expectedResponses = [ + [ + 'code' => 'starck', + 'status_code' => 204 + ], + [ + 'code' => 'dyson', + 'status_code' => 201 + ], + ]; + + $api = $this->createClientByPassword()->getReferenceEntityRecordApi(); + $promise = $api->upsertAsyncList('designer', $records); + Assert::assertInstanceOf(Promise::class, $promise); + + $responses = json_decode($promise->wait()->getBody()->getContents(), true); + + Assert::assertSame($this->server->getLastRequest()->jsonSerialize()[RequestInfo::JSON_KEY_INPUT], json_encode($records)); + Assert::assertSame($expectedResponses, $responses); + } } diff --git a/tests/Api/ReferenceEntityRecord/UpsertReferenceEntityRecordIntegration.php b/tests/Api/ReferenceEntityRecord/UpsertReferenceEntityRecordIntegration.php index 764523d..5776b04 100644 --- a/tests/Api/ReferenceEntityRecord/UpsertReferenceEntityRecordIntegration.php +++ b/tests/Api/ReferenceEntityRecord/UpsertReferenceEntityRecordIntegration.php @@ -7,6 +7,7 @@ use donatj\MockWebServer\RequestInfo; use donatj\MockWebServer\Response; use donatj\MockWebServer\ResponseStack; +use Http\Promise\Promise; use PHPUnit\Framework\Assert; class UpsertReferenceEntityRecordIntegration extends ApiTestCase @@ -39,4 +40,36 @@ public function test_upsert_reference_entity_record() Assert::assertSame($this->server->getLastRequest()->jsonSerialize()[RequestInfo::JSON_KEY_INPUT], json_encode($recordData)); Assert::assertSame(204, $response); } + + public function test_upsert_async_reference_entity_record() + { + $this->server->setResponseOfPath( + '/' . sprintf(ReferenceEntityRecordApi::REFERENCE_ENTITY_RECORD_URI, 'designer', 'starck'), + new ResponseStack( + new Response('', [], 204) + ) + ); + + $recordData = [ + 'code' => 'starck', + 'values' => [ + 'label' => [ + [ + 'channel' => null, + 'locale' => 'en_US', + 'data' => 'Philippe Starck' + ], + ] + ] + ]; + + $api = $this->createClientByPassword()->getReferenceEntityRecordApi(); + $promise = $api->upsertAsync('designer', 'starck', $recordData); + Assert::assertInstanceOf(Promise::class, $promise); + + $response = $promise->wait(); + + Assert::assertSame($this->server->getLastRequest()->jsonSerialize()[RequestInfo::JSON_KEY_INPUT], json_encode($recordData)); + Assert::assertSame(204, $response->getStatusCode()); + } } diff --git a/tests/Api/UpsertListProductTest.php b/tests/Api/UpsertListProductTest.php index ecad688..40a148a 100644 --- a/tests/Api/UpsertListProductTest.php +++ b/tests/Api/UpsertListProductTest.php @@ -3,10 +3,12 @@ namespace Akeneo\Pim\ApiClient\tests\Api; use Akeneo\Pim\ApiClient\Api\ProductApi; +use Akeneo\Pim\ApiClient\Stream\UpsertResourceListResponseFactory; use donatj\MockWebServer\RequestInfo; use donatj\MockWebServer\Response; use donatj\MockWebServer\ResponseStack; use Http\Discovery\Psr17FactoryDiscovery; +use Http\Promise\Promise; use PHPUnit\Framework\Assert; class UpsertListProductTest extends ApiTestCase @@ -47,6 +49,36 @@ public function test_upsert_list() ], $responseLines[2]); } + public function test_upsert_async_list() + { + $upsertListResponseFactory = new UpsertResourceListResponseFactory(); + $api = $this->createClientByPassword()->getProductApi(); + $promise = $api->upsertAsyncList($this->getProductToUpsert()); + + Assert::assertInstanceOf(Promise::class, $promise); + + $response = $upsertListResponseFactory->create($promise->wait()->getBody()); + + Assert::assertSame($this->server->getLastRequest()->jsonSerialize()[RequestInfo::JSON_KEY_INPUT], $this->getProductToUpsertJson()); + + Assert::assertInstanceOf('\Iterator', $response); + + $responseLines = iterator_to_array($response); + Assert::assertCount(2, $responseLines); + + Assert::assertSame([ + 'line' => 1, + 'identifier' => 'docks_black', + 'status_code' => 204, + ], $responseLines[1]); + + Assert::assertSame([ + 'line' => 2, + 'identifier' => 'pumps', + 'status_code' => 201, + ], $responseLines[2]); + } + public function test_upsert_list_from_stream() { $resources = fopen('php://memory', 'w+'); @@ -77,6 +109,42 @@ public function test_upsert_list_from_stream() ], $responseLines[2]); } + public function test_upsert_async_list_from_stream() + { + $resources = fopen('php://memory', 'w+'); + fwrite($resources, $this->getProductToUpsertJson()); + rewind($resources); + + $streamedResources = Psr17FactoryDiscovery::findStreamFactory()->createStreamFromResource($resources); + + $upsertListResponseFactory = new UpsertResourceListResponseFactory(); + $api = $this->createClientByPassword()->getProductApi(); + $promise = $api->upsertAsyncList($streamedResources); + + Assert::assertInstanceOf(Promise::class, $promise); + + $response = $upsertListResponseFactory->create($promise->wait()->getBody()); + + Assert::assertSame($this->server->getLastRequest()->jsonSerialize()[RequestInfo::JSON_KEY_INPUT], $this->getProductToUpsertJson()); + + Assert::assertInstanceOf('\Iterator', $response); + + $responseLines = iterator_to_array($response); + Assert::assertCount(2, $responseLines); + + Assert::assertSame([ + 'line' => 1, + 'identifier' => 'docks_black', + 'status_code' => 204, + ], $responseLines[1]); + + Assert::assertSame([ + 'line' => 2, + 'identifier' => 'pumps', + 'status_code' => 201, + ], $responseLines[2]); + } + private function getProductToUpsertJson(): string { return <<server->setResponseOfPath( + '/' . sprintf(ProductApi::PRODUCT_URI, 'docks_black'), + new ResponseStack( + new Response('', [], 204) + ) + ); + $api = $this->createClientByPassword()->getProductApi(); + $parameters = [ + 'enabled' => false, + 'values' => [ + 'name' => [ + [ + 'locale' => 'en_US', + 'scope' => null, + 'data' => 'Black Docks', + ], + ], + ] + ]; + + $promise = $api->upsertAsync('docks_black', $parameters); + Assert::assertInstanceOf(Promise::class, $promise); + + $response = $promise->wait(); + + Assert::assertSame($this->server->getLastRequest()->jsonSerialize()[RequestInfo::JSON_KEY_INPUT], json_encode($parameters)); + Assert::assertSame(204, $response->getStatusCode()); + } } diff --git a/tests/Client/CachedResourceClientTest.php b/tests/Client/CachedResourceClientTest.php index 443a0a6..60f3beb 100644 --- a/tests/Client/CachedResourceClientTest.php +++ b/tests/Client/CachedResourceClientTest.php @@ -6,14 +6,14 @@ use Akeneo\Pim\ApiClient\Cache\CacheInterface; use Akeneo\Pim\ApiClient\Client\CachedResourceClient; -use Akeneo\Pim\ApiClient\Client\ResourceClient; +use Akeneo\Pim\ApiClient\Client\ResourceClientInterface; use Akeneo\Pim\ApiClient\tests\Api\ApiTestCase; class CachedResourceClientTest extends ApiTestCase { public function test_get_cached_resource(): void { - $resourceClient = $this->createMock(ResourceClient::class); + $resourceClient = $this->createMock(ResourceClientInterface::class); $mockCache = $this->createMock(CacheInterface::class); $uri = 'uri';