From 4073580394300a57274381b96edcf3f2290729e4 Mon Sep 17 00:00:00 2001 From: Akolzin Dmitry Date: Fri, 3 Jul 2020 09:58:31 +0300 Subject: [PATCH] units methods --- lib/RetailCrm/Methods/V5/References.php | 45 +++++++++++++++++++ .../Version5/ApiClientReferenceTest.php | 37 ++++++++++++++- 2 files changed, 81 insertions(+), 1 deletion(-) diff --git a/lib/RetailCrm/Methods/V5/References.php b/lib/RetailCrm/Methods/V5/References.php index a9e4ca7..e1233ed 100644 --- a/lib/RetailCrm/Methods/V5/References.php +++ b/lib/RetailCrm/Methods/V5/References.php @@ -245,4 +245,49 @@ trait References ['courier' => json_encode($courier)] ); } + + /** + * Get units + * + * @throws \InvalidArgumentException + * @throws \RetailCrm\Exception\CurlException + * @throws \RetailCrm\Exception\InvalidJsonException + * + * @return \RetailCrm\Response\ApiResponse + */ + public function unitsList() + { + /* @noinspection PhpUndefinedMethodInspection */ + return $this->client->makeRequest( + '/reference/units', + "GET" + ); + } + + /** + * Edit unit + * + * @param array $unit + * + * @throws \InvalidArgumentException + * @throws \RetailCrm\Exception\CurlException + * @throws \RetailCrm\Exception\InvalidJsonException + * + * @return \RetailCrm\Response\ApiResponse + */ + public function unitsEdit(array $unit) + { + if (empty($unit['code']) || empty($unit['name']) || empty($unit['sym'])) { + throw new \InvalidArgumentException( + '`code`, `name` and `sym` parameters must not be empty.' + ); + } + + /* @noinspection PhpUndefinedMethodInspection */ + return $this->client->makeRequest( + sprintf('/reference/units/%s/edit', $unit['code']), + "POST", + ['unit' => json_encode($unit)] + ); + } } diff --git a/tests/RetailCrm/Tests/Methods/Version5/ApiClientReferenceTest.php b/tests/RetailCrm/Tests/Methods/Version5/ApiClientReferenceTest.php index bf11d11..e85754c 100644 --- a/tests/RetailCrm/Tests/Methods/Version5/ApiClientReferenceTest.php +++ b/tests/RetailCrm/Tests/Methods/Version5/ApiClientReferenceTest.php @@ -137,6 +137,40 @@ class ApiClientReferenceTest extends TestCase } } + /** + * @group reference_v5 + */ + public function testUnitsEditing() + { + $client = static::getApiClient(); + + $unit = [ + 'code' => 'test', + 'name' => 'Test', + 'sym' => 'tst' + ]; + + $response = $client->request->unitsEdit($unit); + + static::assertTrue(in_array($response->getStatusCode(), [200, 201])); + } + + /** + * @group reference_v5 + * @expectedException \InvalidArgumentException + */ + public function testUnitsEditingFail() + { + $client = static::getApiClient(); + + $unit = [ + 'name' => 'Test', + 'sym' => 'tst' + ]; + + $client->request->unitsEdit($unit); + } + /** * @return array */ @@ -155,7 +189,8 @@ class ApiClientReferenceTest extends TestCase ['sites'], ['stores'], ['couriers'], - ['costs'] + ['costs'], + ['units'] ]; }