From 302f9b5a62fa8359fcab6d41b803291ee314d255 Mon Sep 17 00:00:00 2001 From: Lukasz Bajsarowicz Date: Tue, 5 Nov 2024 13:52:41 +0100 Subject: [PATCH 1/8] SwiftOtter-SOP-348 Add missing REST methods to Curl Client --- .../Magento/Framework/HTTP/Client/Curl.php | 35 +++++++++++++++++++ 1 file changed, 35 insertions(+) diff --git a/lib/internal/Magento/Framework/HTTP/Client/Curl.php b/lib/internal/Magento/Framework/HTTP/Client/Curl.php index 7ba4fb915e294..f66bba8111eaa 100644 --- a/lib/internal/Magento/Framework/HTTP/Client/Curl.php +++ b/lib/internal/Magento/Framework/HTTP/Client/Curl.php @@ -246,6 +246,41 @@ public function post($uri, $params) $this->makeRequest("POST", $uri, $params); } + /** + * Make PUT request + * + * @param string $uri + * @param array|string $params + * @return void + */ + public function put($uri, $params) + { + $this->makeRequest("PUT", $uri, $params); + } + + /** + * Make DELETE request + * + * @param string $uri + * @return void + */ + public function delete($uri) + { + $this->makeRequest("DELETE", $uri); + } + + /** + * Make PATCH request + * + * @param string $uri + * @param array|string $params + * @return void + */ + public function patch($uri, $params) + { + $this->makeRequest("PATCH", $uri, $params); + } + /** * Get response headers * From e3668e8a3c50206b81a9b259015be15ae57a2716 Mon Sep 17 00:00:00 2001 From: Lukasz Bajsarowicz Date: Tue, 5 Nov 2024 14:00:10 +0100 Subject: [PATCH 2/8] SwiftOtter-SOP-348 Add missing REST methods: TRACE, HEAD, OPTIONS --- .../Magento/Framework/HTTP/Client/Curl.php | 33 +++++++++++++++++++ 1 file changed, 33 insertions(+) diff --git a/lib/internal/Magento/Framework/HTTP/Client/Curl.php b/lib/internal/Magento/Framework/HTTP/Client/Curl.php index f66bba8111eaa..559e80cbd8770 100644 --- a/lib/internal/Magento/Framework/HTTP/Client/Curl.php +++ b/lib/internal/Magento/Framework/HTTP/Client/Curl.php @@ -281,6 +281,39 @@ public function patch($uri, $params) $this->makeRequest("PATCH", $uri, $params); } + /** + * Make OPTIONS request + * + * @param string $uri + * @return void + */ + public function options($uri) + { + $this->makeRequest("OPTIONS", $uri); + } + + /** + * Make HEAD request + * + * @param string $uri + * @return void + */ + public function head($uri) + { + $this->makeRequest("HEAD", $uri); + } + + /** + * Make TRACE request + * + * @param string $uri + * @return void + */ + public function trace($uri) + { + $this->makeRequest("TRACE", $uri); + } + /** * Get response headers * From 064aa0450f19ec423efe89176e62478ee239b28d Mon Sep 17 00:00:00 2001 From: Lukasz Bajsarowicz Date: Tue, 5 Nov 2024 14:02:49 +0100 Subject: [PATCH 3/8] SwiftOtter-SOP-348 Replace redundant override --- .../Model/SearchEngineVersionReader.php | 2 +- .../Magento/TestFramework/Helper/Amqp.php | 2 ++ .../Magento/TestFramework/Helper/Curl.php | 30 ------------------- 3 files changed, 3 insertions(+), 31 deletions(-) delete mode 100644 dev/tests/integration/framework/Magento/TestFramework/Helper/Curl.php diff --git a/dev/tests/integration/_files/Magento/TestModuleCatalogSearch/Model/SearchEngineVersionReader.php b/dev/tests/integration/_files/Magento/TestModuleCatalogSearch/Model/SearchEngineVersionReader.php index b565caae4e3fc..8775556a90c61 100644 --- a/dev/tests/integration/_files/Magento/TestModuleCatalogSearch/Model/SearchEngineVersionReader.php +++ b/dev/tests/integration/_files/Magento/TestModuleCatalogSearch/Model/SearchEngineVersionReader.php @@ -9,7 +9,7 @@ use Magento\Framework\App\Config\ScopeConfigInterface; use Magento\TestFramework\Helper\Bootstrap; -use Magento\TestFramework\Helper\Curl; +use Magento\Framework\HTTP\Client\Curl; /** * Retrieve search engine version by curl request diff --git a/dev/tests/integration/framework/Magento/TestFramework/Helper/Amqp.php b/dev/tests/integration/framework/Magento/TestFramework/Helper/Amqp.php index 0aa9850e6a189..5cac41ae460cc 100644 --- a/dev/tests/integration/framework/Magento/TestFramework/Helper/Amqp.php +++ b/dev/tests/integration/framework/Magento/TestFramework/Helper/Amqp.php @@ -8,6 +8,8 @@ namespace Magento\TestFramework\Helper; +use Magento\Framework\HTTP\Client\Curl; + /** * Helper class to access RabbitMQ server configuration */ diff --git a/dev/tests/integration/framework/Magento/TestFramework/Helper/Curl.php b/dev/tests/integration/framework/Magento/TestFramework/Helper/Curl.php deleted file mode 100644 index 62b753cf5d344..0000000000000 --- a/dev/tests/integration/framework/Magento/TestFramework/Helper/Curl.php +++ /dev/null @@ -1,30 +0,0 @@ -makeRequest("DELETE", $uri); - } -} From 0ec2621986954cbf2d5905f574ee7804a984aa0c Mon Sep 17 00:00:00 2001 From: Lukasz Bajsarowicz Date: Tue, 5 Nov 2024 15:11:57 +0100 Subject: [PATCH 4/8] SwiftOtter-SOP-348 Resolve issues with Static checks --- .../framework/Magento/TestFramework/Helper/Amqp.php | 12 ++++++------ lib/internal/Magento/Framework/HTTP/Client/Curl.php | 1 - 2 files changed, 6 insertions(+), 7 deletions(-) diff --git a/dev/tests/integration/framework/Magento/TestFramework/Helper/Amqp.php b/dev/tests/integration/framework/Magento/TestFramework/Helper/Amqp.php index 5cac41ae460cc..f75b5a49503e9 100644 --- a/dev/tests/integration/framework/Magento/TestFramework/Helper/Amqp.php +++ b/dev/tests/integration/framework/Magento/TestFramework/Helper/Amqp.php @@ -15,12 +15,12 @@ */ class Amqp { - const CONFIG_PATH_HOST = 'queue/amqp/host'; - const CONFIG_PATH_USER = 'queue/amqp/user'; - const CONFIG_PATH_PASSWORD = 'queue/amqp/password'; - const DEFAULT_MANAGEMENT_PROTOCOL = 'http'; - const DEFAULT_MANAGEMENT_PORT = '15672'; - const DEFAULT_VIRTUALHOST = '/'; + public const CONFIG_PATH_HOST = 'queue/amqp/host'; + public const CONFIG_PATH_USER = 'queue/amqp/user'; + public const CONFIG_PATH_PASSWORD = 'queue/amqp/password'; + public const DEFAULT_MANAGEMENT_PROTOCOL = 'http'; + public const DEFAULT_MANAGEMENT_PORT = '15672'; + public const DEFAULT_VIRTUALHOST = '/'; /** * @var Curl diff --git a/lib/internal/Magento/Framework/HTTP/Client/Curl.php b/lib/internal/Magento/Framework/HTTP/Client/Curl.php index 559e80cbd8770..a88cc8362e555 100644 --- a/lib/internal/Magento/Framework/HTTP/Client/Curl.php +++ b/lib/internal/Magento/Framework/HTTP/Client/Curl.php @@ -11,7 +11,6 @@ /** * Class to work with HTTP protocol using curl library * - * @author Magento Core Team * @SuppressWarnings(PHPMD.ExcessiveClassComplexity) * @api */ From 4297a88be0b12755ef71cc79b8822796528afad2 Mon Sep 17 00:00:00 2001 From: engcom-Dash Date: Fri, 22 Nov 2024 16:30:47 +0530 Subject: [PATCH 5/8] 39330: Add optional payload support for DELETE, OPTIONS, HEAD, and add CONNECT method --- .../Model/SearchEngineVersionReader.php | 4 +-- .../Magento/TestFramework/Helper/Amqp.php | 5 ++- .../Magento/Framework/HTTP/Client/Curl.php | 34 +++++++++++++------ 3 files changed, 28 insertions(+), 15 deletions(-) diff --git a/dev/tests/integration/_files/Magento/TestModuleCatalogSearch/Model/SearchEngineVersionReader.php b/dev/tests/integration/_files/Magento/TestModuleCatalogSearch/Model/SearchEngineVersionReader.php index 8775556a90c61..40563d428ac28 100644 --- a/dev/tests/integration/_files/Magento/TestModuleCatalogSearch/Model/SearchEngineVersionReader.php +++ b/dev/tests/integration/_files/Magento/TestModuleCatalogSearch/Model/SearchEngineVersionReader.php @@ -1,7 +1,7 @@ makeRequest("DELETE", $uri); + $this->makeRequest("DELETE", $uri, $params); } /** @@ -284,22 +284,24 @@ public function patch($uri, $params) * Make OPTIONS request * * @param string $uri + * @param array|string $params * @return void */ - public function options($uri) + public function options(string $uri, array|string $params = []) { - $this->makeRequest("OPTIONS", $uri); + $this->makeRequest("OPTIONS", $uri, $params); } /** * Make HEAD request * * @param string $uri + * @param array|string $params * @return void */ - public function head($uri) + public function head(string $uri, array|string $params = []) { - $this->makeRequest("HEAD", $uri); + $this->makeRequest("HEAD", $uri, $params); } /** @@ -308,11 +310,23 @@ public function head($uri) * @param string $uri * @return void */ - public function trace($uri) + public function trace(string $uri) { $this->makeRequest("TRACE", $uri); } + /** + * Make CONNECT request + * + * @param string $uri + * @param array|string $params + * @return void + */ + public function connect(string $uri, array|string $params = []) + { + $this->makeRequest("CONNECT", $uri, $params); + } + /** * Get response headers * From 9f32ea37d7b87e104870551b717416dd9e844835 Mon Sep 17 00:00:00 2001 From: engcom-Dash Date: Thu, 28 Nov 2024 15:13:37 +0530 Subject: [PATCH 6/8] 39330: apply suggested changes and revert deleted file with deprecated tag --- .../Magento/TestFramework/Helper/Amqp.php | 14 +++++--- .../Magento/TestFramework/Helper/Curl.php | 35 +++++++++++++++++++ 2 files changed, 44 insertions(+), 5 deletions(-) create mode 100644 dev/tests/integration/framework/Magento/TestFramework/Helper/Curl.php diff --git a/dev/tests/integration/framework/Magento/TestFramework/Helper/Amqp.php b/dev/tests/integration/framework/Magento/TestFramework/Helper/Amqp.php index 92a469f2b1f8b..56eacb6a6835f 100644 --- a/dev/tests/integration/framework/Magento/TestFramework/Helper/Amqp.php +++ b/dev/tests/integration/framework/Magento/TestFramework/Helper/Amqp.php @@ -8,6 +8,7 @@ namespace Magento\TestFramework\Helper; use Magento\Framework\HTTP\Client\Curl; +use Magento\Framework\App\DeploymentConfig; /** * Helper class to access RabbitMQ server configuration @@ -27,7 +28,7 @@ class Amqp private $curl; /** - * @var \Magento\Framework\App\DeploymentConfig + * @var DeploymentConfig */ private $deploymentConfig; @@ -43,14 +44,17 @@ class Amqp /** * Initialize dependencies. - * @param \Magento\Framework\App\DeploymentConfig $deploymentConfig + * @param DeploymentConfig $deploymentConfig + * @param Curl $curl */ public function __construct( - \Magento\Framework\App\DeploymentConfig $deploymentConfig = null + DeploymentConfig $deploymentConfig = null, + Curl $curl = null ) { $this->deploymentConfig = $deploymentConfig ?? \Magento\TestFramework\Helper\Bootstrap::getObjectManager() - ->get(\Magento\Framework\App\DeploymentConfig::class); - $this->curl = new Curl(); + ->get(DeploymentConfig::class); + $this->curl = $curl ?? \Magento\TestFramework\Helper\Bootstrap::getObjectManager() + ->get(Curl::class); $this->curl->setCredentials( $this->deploymentConfig->get(self::CONFIG_PATH_USER), $this->deploymentConfig->get(self::CONFIG_PATH_PASSWORD) diff --git a/dev/tests/integration/framework/Magento/TestFramework/Helper/Curl.php b/dev/tests/integration/framework/Magento/TestFramework/Helper/Curl.php new file mode 100644 index 0000000000000..e1e7075092414 --- /dev/null +++ b/dev/tests/integration/framework/Magento/TestFramework/Helper/Curl.php @@ -0,0 +1,35 @@ +makeRequest("DELETE", $uri, $params); + } +} From e71d63b52fec1cdc84dc19f9803e09e0cfdf45a3 Mon Sep 17 00:00:00 2001 From: engcom-Dash Date: Thu, 28 Nov 2024 15:17:50 +0530 Subject: [PATCH 7/8] 39330: update copyright tag --- .../framework/Magento/TestFramework/Helper/Curl.php | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/dev/tests/integration/framework/Magento/TestFramework/Helper/Curl.php b/dev/tests/integration/framework/Magento/TestFramework/Helper/Curl.php index e1e7075092414..1cf6ffbf391e7 100644 --- a/dev/tests/integration/framework/Magento/TestFramework/Helper/Curl.php +++ b/dev/tests/integration/framework/Magento/TestFramework/Helper/Curl.php @@ -1,9 +1,8 @@ Date: Mon, 2 Dec 2024 11:29:00 +0100 Subject: [PATCH 8/8] SwiftOtter-SOP-348 Match CURL Client to RFC-9110 and RFC-5789 --- .../Magento/TestFramework/Helper/Curl.php | 18 +-------- .../Magento/Framework/HTTP/Client/Curl.php | 39 +++++++++++++------ 2 files changed, 28 insertions(+), 29 deletions(-) diff --git a/dev/tests/integration/framework/Magento/TestFramework/Helper/Curl.php b/dev/tests/integration/framework/Magento/TestFramework/Helper/Curl.php index 1cf6ffbf391e7..46766477e359d 100644 --- a/dev/tests/integration/framework/Magento/TestFramework/Helper/Curl.php +++ b/dev/tests/integration/framework/Magento/TestFramework/Helper/Curl.php @@ -11,24 +11,8 @@ /** * @deprecated All the curl methods are included in \Magento\Framework\HTTP\Client\Curl class. - * @see \Magento\Framework\HTTP\Client\Curl::delete() when you want to use delete method + * @see \Magento\Framework\HTTP\Client\Curl */ class Curl extends CurlLibrary { - /** - * Make DELETE request - * - * String type was added to parameter $param in order to support sending JSON or XML requests. - * This feature was added base on Community Pull Request https://github.com/magento/magento2/pull/8373 - * - * @param string $uri - * @param array|string $params - * @return void - * - * @see \Magento\Framework\HTTP\Client#post($uri, $params) - */ - public function delete(string $uri, array|string $params = []) - { - $this->makeRequest("DELETE", $uri, $params); - } } diff --git a/lib/internal/Magento/Framework/HTTP/Client/Curl.php b/lib/internal/Magento/Framework/HTTP/Client/Curl.php index e7ee962ab9ca8..28fa37d6d3c15 100644 --- a/lib/internal/Magento/Framework/HTTP/Client/Curl.php +++ b/lib/internal/Magento/Framework/HTTP/Client/Curl.php @@ -221,6 +221,8 @@ public function removeCookies() * * @param string $uri uri relative to host, ex. "/index.php" * @return void + * + * @url https://www.rfc-editor.org/rfc/rfc9110.html#section-9.3.1 */ public function get($uri) { @@ -237,7 +239,8 @@ public function get($uri) * @param array|string $params * @return void * - * @see \Magento\Framework\HTTP\Client#post($uri, $params) + * @see \Magento\Framework\HTTP\Client::post($uri, $params) + * @url https://www.rfc-editor.org/rfc/rfc9110.html#section-9.3.3 */ public function post($uri, $params) { @@ -250,8 +253,10 @@ public function post($uri, $params) * @param string $uri * @param array|string $params * @return void + * + * @url https://www.rfc-editor.org/rfc/rfc9110.html#section-9.3.4 */ - public function put($uri, $params) + public function put(string $uri, string|array $params): void { $this->makeRequest("PUT", $uri, $params); } @@ -262,8 +267,10 @@ public function put($uri, $params) * @param string $uri * @param array|string $params * @return void + * + * @url https://www.rfc-editor.org/rfc/rfc9110.html#section-9.3.5 */ - public function delete(string $uri, array|string $params = []) + public function delete(string $uri, array|string $params = []): void { $this->makeRequest("DELETE", $uri, $params); } @@ -274,8 +281,10 @@ public function delete(string $uri, array|string $params = []) * @param string $uri * @param array|string $params * @return void + * + * @url https://www.rfc-editor.org/info/rfc5789 */ - public function patch($uri, $params) + public function patch(string $uri, array|string $params): void { $this->makeRequest("PATCH", $uri, $params); } @@ -286,8 +295,10 @@ public function patch($uri, $params) * @param string $uri * @param array|string $params * @return void + * + * @url https://www.rfc-editor.org/rfc/rfc9110.html#section-9.3.7 */ - public function options(string $uri, array|string $params = []) + public function options(string $uri, array|string $params = []): void { $this->makeRequest("OPTIONS", $uri, $params); } @@ -296,12 +307,13 @@ public function options(string $uri, array|string $params = []) * Make HEAD request * * @param string $uri - * @param array|string $params * @return void + * + * @url https://www.rfc-editor.org/rfc/rfc9110.html#section-9.3.2 */ - public function head(string $uri, array|string $params = []) + public function head(string $uri): void { - $this->makeRequest("HEAD", $uri, $params); + $this->makeRequest("HEAD", $uri); } /** @@ -309,8 +321,10 @@ public function head(string $uri, array|string $params = []) * * @param string $uri * @return void + * + * @url https://www.rfc-editor.org/rfc/rfc9110.html#section-9.3.8 */ - public function trace(string $uri) + public function trace(string $uri): void { $this->makeRequest("TRACE", $uri); } @@ -319,12 +333,13 @@ public function trace(string $uri) * Make CONNECT request * * @param string $uri - * @param array|string $params * @return void + * + * @url https://www.rfc-editor.org/rfc/rfc9110.html#section-9.3.6 */ - public function connect(string $uri, array|string $params = []) + public function connect(string $uri): void { - $this->makeRequest("CONNECT", $uri, $params); + $this->makeRequest("CONNECT", $uri); } /**