From 8476f8946e6257e2265802c4b9724ad269050802 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=D0=92=D0=BB=D0=B0=D0=B4=D0=B8=D0=BC=D0=B8=D1=80=20=D0=9A?= =?UTF-8?q?=D0=BE=D0=BB=D1=87=D0=B8=D0=BD?= Date: Mon, 24 Jul 2023 17:57:42 +0300 Subject: [PATCH] Fixed files/upload issue --- src/Handler/Request/RequestDataHandler.php | 5 ++++- tests/src/ResourceGroup/FilesTest.php | 2 +- 2 files changed, 5 insertions(+), 2 deletions(-) diff --git a/src/Handler/Request/RequestDataHandler.php b/src/Handler/Request/RequestDataHandler.php index a697a14..d42636d 100644 --- a/src/Handler/Request/RequestDataHandler.php +++ b/src/Handler/Request/RequestDataHandler.php @@ -15,6 +15,7 @@ use RetailCrm\Api\Enum\RequestMethod; use RetailCrm\Api\Exception\Client\HandlerException; use RetailCrm\Api\Handler\AbstractHandler; use RetailCrm\Api\Interfaces\FormEncoderInterface; +use RetailCrm\Api\Model\Request\Files\FilesUploadRequest; use RetailCrm\Api\Model\RequestData; use Throwable; @@ -76,7 +77,9 @@ class RequestDataHandler extends AbstractHandler } if ('' !== $formData) { - if (static::queryShouldBeUsed($item->request->getMethod())) { + if ($item->requestModel instanceof FilesUploadRequest) { + $item->request = $item->request->withBody($item->requestModel->file); + } elseif (static::queryShouldBeUsed($item->request->getMethod())) { $item->request = $item->request->withUri( $item->request->getUri()->withQuery($formData) ); diff --git a/tests/src/ResourceGroup/FilesTest.php b/tests/src/ResourceGroup/FilesTest.php index edd1e4f..08f2472 100644 --- a/tests/src/ResourceGroup/FilesTest.php +++ b/tests/src/ResourceGroup/FilesTest.php @@ -98,7 +98,7 @@ EOF; $request = new FilesUploadRequest($file); $mock->matchMethod(RequestMethod::POST) - ->matchBody(static::encodeForm($request)) + ->matchBody($file) ->reply(200) ->withBody($json);