From 0c213eac0e25fff312bd886b11e2acfbd41e5d77 Mon Sep 17 00:00:00 2001 From: Alex Lushpai Date: Thu, 14 Apr 2016 22:22:18 +0300 Subject: [PATCH 01/15] travis --- .travis.yml | 6 ++++++ 1 file changed, 6 insertions(+) create mode 100644 .travis.yml diff --git a/.travis.yml b/.travis.yml new file mode 100644 index 0000000..a4dbf87 --- /dev/null +++ b/.travis.yml @@ -0,0 +1,6 @@ +language: php +php: + - '5.4' + - '5.5' + - '5.6' +script: phpunit From 338452a16991df787773359d38fe25078383fd8c Mon Sep 17 00:00:00 2001 From: Alex Lushpai Date: Thu, 14 Apr 2016 22:28:55 +0300 Subject: [PATCH 02/15] travis update --- .travis.yml | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/.travis.yml b/.travis.yml index a4dbf87..a03cbba 100644 --- a/.travis.yml +++ b/.travis.yml @@ -1,6 +1,16 @@ language: php + +cache: + directories: + - $HOME/.composer/cache + php: - '5.4' - '5.5' - '5.6' + +before_script: + - flags="--prefer-dist" + - composer install $flags + script: phpunit From 494a4d34329eb452b0954e9de85f1cdeb800bed1 Mon Sep 17 00:00:00 2001 From: Alex Lushpai Date: Thu, 14 Apr 2016 22:40:33 +0300 Subject: [PATCH 03/15] travis update --- .travis.yml | 1 + composer.json | 6 +++--- phpunit.xml.dist | 12 ++++++------ 3 files changed, 10 insertions(+), 9 deletions(-) diff --git a/.travis.yml b/.travis.yml index a03cbba..84d01ac 100644 --- a/.travis.yml +++ b/.travis.yml @@ -5,6 +5,7 @@ cache: - $HOME/.composer/cache php: + - '5.3' - '5.4' - '5.5' - '5.6' diff --git a/composer.json b/composer.json index 9bf2ea4..21506ea 100644 --- a/composer.json +++ b/composer.json @@ -16,10 +16,10 @@ "ext-curl": "*" }, "require-dev": { - "phpunit/phpunit": "5.2.*", - "phpunit/php-code-coverage": "3.3.0", + "phpunit/phpunit": "4.8.0", + "phpunit/php-code-coverage": "3.0.0", "phpunit/php-invoker": "1.1.4", - "phpmd/phpmd": "2.4.*", + "phpmd/phpmd": "2.3.0", "sebastian/phpcpd": "2.0.*", "sebastian/phpdcd": "1.0.*", "squizlabs/php_codesniffer": "2.5.*", diff --git a/phpunit.xml.dist b/phpunit.xml.dist index 6097b7b..d203a3b 100644 --- a/phpunit.xml.dist +++ b/phpunit.xml.dist @@ -10,12 +10,12 @@ - - - - - - + + + + + + From 4ccf30d58823e45e3bcc857e5b6ce4b0fa30da58 Mon Sep 17 00:00:00 2001 From: Alex Lushpai Date: Thu, 14 Apr 2016 22:44:50 +0300 Subject: [PATCH 04/15] travis update --- composer.json | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) diff --git a/composer.json b/composer.json index 21506ea..6eeeffa 100644 --- a/composer.json +++ b/composer.json @@ -17,13 +17,11 @@ }, "require-dev": { "phpunit/phpunit": "4.8.0", - "phpunit/php-code-coverage": "3.0.0", - "phpunit/php-invoker": "1.1.4", "phpmd/phpmd": "2.3.0", "sebastian/phpcpd": "2.0.*", "sebastian/phpdcd": "1.0.*", "squizlabs/php_codesniffer": "2.5.*", - "apigen/apigen": "4.1.*" + "apigen/apigen": "2.8.1" }, "support": { "email": "support@retailcrm.pro" From 546010b337489042348d2b705d6a373a2d7b09b9 Mon Sep 17 00:00:00 2001 From: Alex Lushpai Date: Thu, 14 Apr 2016 22:53:59 +0300 Subject: [PATCH 05/15] travis update --- .travis.yml | 2 +- composer.json | 8 +++++--- phpunit.xml.dist | 2 +- 3 files changed, 7 insertions(+), 5 deletions(-) diff --git a/.travis.yml b/.travis.yml index 84d01ac..4d6ff60 100644 --- a/.travis.yml +++ b/.travis.yml @@ -11,7 +11,7 @@ php: - '5.6' before_script: - - flags="--prefer-dist" + - flags="--prefer-dist --no-dev" - composer install $flags script: phpunit diff --git a/composer.json b/composer.json index 6eeeffa..9bf2ea4 100644 --- a/composer.json +++ b/composer.json @@ -16,12 +16,14 @@ "ext-curl": "*" }, "require-dev": { - "phpunit/phpunit": "4.8.0", - "phpmd/phpmd": "2.3.0", + "phpunit/phpunit": "5.2.*", + "phpunit/php-code-coverage": "3.3.0", + "phpunit/php-invoker": "1.1.4", + "phpmd/phpmd": "2.4.*", "sebastian/phpcpd": "2.0.*", "sebastian/phpdcd": "1.0.*", "squizlabs/php_codesniffer": "2.5.*", - "apigen/apigen": "2.8.1" + "apigen/apigen": "4.1.*" }, "support": { "email": "support@retailcrm.pro" diff --git a/phpunit.xml.dist b/phpunit.xml.dist index d203a3b..a8b949e 100644 --- a/phpunit.xml.dist +++ b/phpunit.xml.dist @@ -14,7 +14,7 @@ - + From d26f609e9fac29d3d639d70e5a7b025f7e2e37c2 Mon Sep 17 00:00:00 2001 From: Alex Lushpai Date: Thu, 14 Apr 2016 23:11:51 +0300 Subject: [PATCH 06/15] travis update, packs test update --- phpunit.xml.dist | 2 +- tests/RetailCrm/Tests/ApiClientPacksTest.php | 69 ++++++++++++++++++-- 2 files changed, 63 insertions(+), 8 deletions(-) diff --git a/phpunit.xml.dist b/phpunit.xml.dist index a8b949e..e4bb52c 100644 --- a/phpunit.xml.dist +++ b/phpunit.xml.dist @@ -6,7 +6,7 @@ colors="true" verbose="true" processIsolation="false" - stopOnFailure="true"> + stopOnFailure="false"> diff --git a/tests/RetailCrm/Tests/ApiClientPacksTest.php b/tests/RetailCrm/Tests/ApiClientPacksTest.php index cc51764..ac13585 100644 --- a/tests/RetailCrm/Tests/ApiClientPacksTest.php +++ b/tests/RetailCrm/Tests/ApiClientPacksTest.php @@ -1,13 +1,52 @@ + * @license https://opensource.org/licenses/MIT MIT License + * @link http://www.retailcrm.ru/docs/Developers/ApiVersion3 + */ + namespace RetailCrm\Tests; use RetailCrm\Test\TestCase; +/** + * Class ApiClientPacksTest + * + * @category RetailCrm + * @package RetailCrm + * @author RetailCrm + * @license https://opensource.org/licenses/MIT MIT License + * @link http://www.retailcrm.ru/docs/Developers/ApiVersion3 + */ class ApiClientPacksTest extends TestCase { + private $_packId; + /** - * @group integration + * ApiClientPacksTest constructor. + * + * @param null|string $name name + * @param array $data data + * @param string $dataName dataName + */ + public function __construct($name = null, array $data = array(), $dataName = '') + { + parent::__construct($name, $data, $dataName); + $this->_packId = __DIR__ . '/../../../pack.tmp'; + } + + /** + * Test packs history + * + * @group integration + * @return void */ public function testOrdersPacksHistory() { @@ -28,7 +67,10 @@ class ApiClientPacksTest extends TestCase } /** - * @group integration + * Test packs create + * + * @group integration + * @return void */ public function testOrdersPacksCreate() { @@ -40,13 +82,17 @@ class ApiClientPacksTest extends TestCase ); $response = $client->ordersPacksCreate($pack); + file_put_contents($this->_packId, $response["id"]); $this->assertInstanceOf('RetailCrm\Response\ApiResponse', $response); $this->assertEquals(201, $response->getStatusCode()); $this->assertTrue($response->success); } /** - * @group integration + * Test packs failed create + * + * @group integration + * @return void */ public function testOrdersPacksCreateFailed() { @@ -64,28 +110,37 @@ class ApiClientPacksTest extends TestCase } /** - * @group integration + * Test packs get + * + * @group integration + * @return void */ public function testOrdersPacksGet() { $client = static::getApiClient(); - $response = $client->ordersPacksGet(1); + $packId = file_get_contents($this->_packId); + $response = $client->ordersPacksGet($packId); $this->assertInstanceOf('RetailCrm\Response\ApiResponse', $response); $this->assertEquals(200, $response->getStatusCode()); $this->assertTrue($response->success); } /** - * @group integration + * Test packs delete + * + * @group integration + * @return void */ public function testOrdersPacksDelete() { $client = static::getApiClient(); - $response = $client->ordersPacksDelete(1); + $packId = file_get_contents($this->_packId); + $response = $client->ordersPacksDelete($packId); $this->assertInstanceOf('RetailCrm\Response\ApiResponse', $response); $this->assertEquals(200, $response->getStatusCode()); $this->assertTrue($response->success); + unlink($this->_packId); } } From a6e5afa1657f0c5c4baef4864c3b16164c0b19ee Mon Sep 17 00:00:00 2001 From: Alex Lushpai Date: Mon, 6 Jun 2016 17:53:05 +0300 Subject: [PATCH 07/15] v4 initial commit, users, stores & telephony method updated --- composer.json | 2 +- lib/RetailCrm/ApiClient.php | 289 +++++++++++++++++++++++------------- 2 files changed, 190 insertions(+), 101 deletions(-) diff --git a/composer.json b/composer.json index 9bf2ea4..11898b4 100644 --- a/composer.json +++ b/composer.json @@ -33,7 +33,7 @@ }, "extra": { "branch-alias": { - "dev-master": "3.0.x-dev" + "dev-master": "4.0.x-dev" } }, "config": { diff --git a/lib/RetailCrm/ApiClient.php b/lib/RetailCrm/ApiClient.php index de8ea4c..74fece3 100644 --- a/lib/RetailCrm/ApiClient.php +++ b/lib/RetailCrm/ApiClient.php @@ -31,7 +31,7 @@ use RetailCrm\Response\ApiResponse; class ApiClient { - const VERSION = 'v3'; + const VERSION = 'v4'; protected $client; @@ -53,7 +53,7 @@ class ApiClient */ public function __construct($url, $apiKey, $site = null) { - if ('/' !== substr($url, strlen($url) - 1, 1)) { + if ('/' !== $url[strlen($url) - 1]) { $url .= '/'; } @@ -63,6 +63,56 @@ class ApiClient $this->siteCode = $site; } + /** + * Returns users list + * + * @param array $filter + * @param null $page + * @param null $limit + * + * @throws \RetailCrm\Exception\InvalidJsonException + * @throws \RetailCrm\Exception\CurlException + * @throws \InvalidArgumentException + * + * @return ApiResponse + */ + public function usersList(array $filter = array(), $page = null, $limit = null) + { + $parameters = array(); + + if (count($filter)) { + $parameters['filter'] = $filter; + } + if (null !== $page) { + $parameters['page'] = (int) $page; + } + if (null !== $limit) { + $parameters['limit'] = (int) $limit; + } + + return $this->client->makeRequest( + '/users', + Client::METHOD_GET, + $parameters + ); + } + + /** + * Returns user data + * + * @param integer $id user ID + * + * @throws \RetailCrm\Exception\InvalidJsonException + * @throws \RetailCrm\Exception\CurlException + * @throws \InvalidArgumentException + * + * @return ApiResponse + */ + public function usersGet($id) + { + return $this->client->makeRequest("/users/$id", Client::METHOD_GET); + } + /** * Returns filtered orders list * @@ -151,53 +201,6 @@ class ApiClient ); } - /** - * Returns a orders history - * - * @param \DateTime $startDate (default: null) - * @param \DateTime $endDate (default: null) - * @param int $limit (default: 100) - * @param int $offset (default: 0) - * @param bool $skipMyChanges (default: true) - * - * @throws \InvalidArgumentException - * @throws \RetailCrm\Exception\CurlException - * @throws \RetailCrm\Exception\InvalidJsonException - * - * @return ApiResponse - */ - public function ordersHistory( - \DateTime $startDate = null, - \DateTime $endDate = null, - $limit = 100, - $offset = 0, - $skipMyChanges = true - ) { - $parameters = array(); - - if ($startDate) { - $parameters['startDate'] = $startDate->format('Y-m-d H:i:s'); - } - if ($endDate) { - $parameters['endDate'] = $endDate->format('Y-m-d H:i:s'); - } - if ($limit) { - $parameters['limit'] = (int) $limit; - } - if ($offset) { - $parameters['offset'] = (int) $offset; - } - if ($skipMyChanges) { - $parameters['skipMyChanges'] = (bool) $skipMyChanges; - } - - return $this->client->makeRequest( - '/orders/history', - Client::METHOD_GET, - $parameters - ); - } - /** * Returns statuses of the orders * @@ -210,10 +213,8 @@ class ApiClient * * @return ApiResponse */ - public function ordersStatuses( - array $ids = array(), - array $externalIds = array() - ) { + public function ordersStatuses(array $ids = array(), array $externalIds = array()) + { $parameters = array(); if (count($ids)) { @@ -333,11 +334,8 @@ class ApiClient * * @return ApiResponse */ - public function customersList( - array $filter = array(), - $page = null, - $limit = null - ) { + public function customersList(array $filter = array(), $page = null, $limit = null) + { $parameters = array(); if (count($filter)) { @@ -513,11 +511,8 @@ class ApiClient * * @return ApiResponse */ - public function ordersPacksList( - array $filter = array(), - $page = null, - $limit = null - ) { + public function ordersPacksList(array $filter = array(), $page = null, $limit = null) + { $parameters = array(); if (count($filter)) { @@ -577,11 +572,8 @@ class ApiClient * * @return ApiResponse */ - public function ordersPacksHistory( - array $filter = array(), - $page = null, - $limit = null - ) { + public function ordersPacksHistory(array $filter = array(), $page = null, $limit = null) + { $parameters = array(); if (count($filter)) { @@ -687,11 +679,8 @@ class ApiClient * * @return ApiResponse */ - public function storeInventories( - array $filter = array(), - $page = null, - $limit = null - ) { + public function storeInventories(array $filter = array(), $page = null, $limit = null) + { $parameters = array(); if (count($filter)) { @@ -711,6 +700,56 @@ class ApiClient ); } + /** + * Get store settings + * + * @param string $code get settings code + * + * @return ApiResponse + * @throws \RetailCrm\Exception\InvalidJsonException + * @throws \RetailCrm\Exception\CurlException + * @throws \InvalidArgumentException + * + * @return ApiResponse + */ + public function storeSettingsGet($code) + { + if (empty($code)) { + throw new \InvalidArgumentException('Parameter `code` must be set'); + } + + return $this->client->makeRequest( + "/store/settings/$code", + Client::METHOD_GET + ); + } + + /** + * Edit store configuration + * + * @param array $configuration + * + * @throws \RetailCrm\Exception\InvalidJsonException + * @throws \RetailCrm\Exception\CurlException + * @throws \InvalidArgumentException + * + * @return ApiResponse + */ + public function storeSettingsEdit(array $configuration) + { + if (!count($configuration) || empty($configuration['code'])) { + throw new \InvalidArgumentException( + 'Parameter `configuration` must contains a data & configuration `code` must be set' + ); + } + + return $this->client->makeRequest( + sprintf('/store/settings/%s/edit', $configuration['code']), + Client::METHOD_POST, + $configuration + ); + } + /** * Upload store inventories * @@ -738,6 +777,40 @@ class ApiClient ); } + /** + * Get products + * + * @param array $filter (default: array()) + * @param int $page (default: null) + * @param int $limit (default: null) + * + * @throws \InvalidArgumentException + * @throws \RetailCrm\Exception\CurlException + * @throws \RetailCrm\Exception\InvalidJsonException + * + * @return ApiResponse + */ + public function storeProducts(array $filter = array(), $page = null, $limit = null) + { + $parameters = array(); + + if (count($filter)) { + $parameters['filter'] = $filter; + } + if (null !== $page) { + $parameters['page'] = (int) $page; + } + if (null !== $limit) { + $parameters['limit'] = (int) $limit; + } + + return $this->client->makeRequest( + '/store/products', + Client::METHOD_GET, + $parameters + ); + } + /** * Returns available county list * @@ -1209,7 +1282,29 @@ class ApiClient } /** - * Telephony settings + * Get telephony settings + * + * @param string $code + * + * @throws \RetailCrm\Exception\InvalidJsonException + * @throws \RetailCrm\Exception\CurlException + * @throws \InvalidArgumentException + * + * @return ApiResponse + */ + public function telephonySettingsGet($code) + { + if (empty($code)) { + throw new \InvalidArgumentException('Parameter `code` must be set'); + } + + return $this->client->makeRequest( + "/telephony/settings/$code", + Client::METHOD_GET + ); + } + /** + * Edit telephony settings * * @param string $code symbolic code * @param string $clientId client id @@ -1224,14 +1319,8 @@ class ApiClient * * @return ApiResponse */ - public function telephonySettings( - $code, - $clientId, - $active = false, - $makeCallUrl = false, - $name = false, - $image = false - ) { + public function telephonySettingsEdit($code, $clientId, $active = false, $makeCallUrl = false, $name = false, $image = false) + { if (!isset($code)) { throw new \InvalidArgumentException('Code must be set'); } @@ -1267,29 +1356,12 @@ class ApiClient } return $this->client->makeRequest( - "/telephony/setting/$code", + "/telephony/setting/$code/edit", Client::METHOD_POST, $parameters ); } - /** - * Update CRM basic statistic - * - * @throws \InvalidArgumentException - * @throws \RetailCrm\Exception\CurlException - * @throws \RetailCrm\Exception\InvalidJsonException - * - * @return ApiResponse - */ - public function statisticUpdate() - { - return $this->client->makeRequest( - '/statistic/update', - Client::METHOD_GET - ); - } - /** * Call event * @@ -1386,6 +1458,23 @@ class ApiClient ); } + /** + * Update CRM basic statistic + * + * @throws \InvalidArgumentException + * @throws \RetailCrm\Exception\CurlException + * @throws \RetailCrm\Exception\InvalidJsonException + * + * @return ApiResponse + */ + public function statisticUpdate() + { + return $this->client->makeRequest( + '/statistic/update', + Client::METHOD_GET + ); + } + /** * Return current site * From a9b60cfd6252590b25b1278b847f3b2a3514f454 Mon Sep 17 00:00:00 2001 From: Alex Lushpai Date: Mon, 6 Jun 2016 17:54:08 +0300 Subject: [PATCH 08/15] update readme --- README.md | 2 +- README.ru.md | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/README.md b/README.md index b60dbed..afaa14c 100644 --- a/README.md +++ b/README.md @@ -15,7 +15,7 @@ Use [API documentation](http://retailcrm.github.io/api-client-php) 2) Run into your project directory: ```bash -composer require retailcrm/api-client-php ~3.0.0 --no-dev +composer require retailcrm/api-client-php ~4.0.0 --no-dev ``` If you have not used `composer` before, include autoloader into your project. diff --git a/README.ru.md b/README.ru.md index 37ab91e..5652dc6 100644 --- a/README.ru.md +++ b/README.ru.md @@ -15,7 +15,7 @@ PHP-клиент для работы с [retailCRM API](http://www.retailcrm.ru/ 2) Выполните в папке проекта: ```bash -composer require retailcrm/api-client-php ~3.0.0 --no-dev +composer require retailcrm/api-client-php ~4.0.0 --no-dev ``` В конфиг `composer.json` вашего проекта будет добавлена библиотека `retailcrm/api-client-php`, которая установится в папку `vendor/`. При отсутствии файла конфига или папки с вендорами они будут созданы. From de70ffd2bd1269de9a6f8e2400c455aea721b4f6 Mon Sep 17 00:00:00 2001 From: Alex Lushpai Date: Mon, 11 Jul 2016 14:22:06 +0300 Subject: [PATCH 09/15] first alpha --- README.md | 2 +- README.ru.md | 2 +- composer.json | 10 --- lib/RetailCrm/ApiClient.php | 138 ++++++++++++++++++++++++++++++++++++ 4 files changed, 140 insertions(+), 12 deletions(-) diff --git a/README.md b/README.md index afaa14c..d8bab15 100644 --- a/README.md +++ b/README.md @@ -1,6 +1,6 @@ # retailCRM API PHP client -PHP-client for [retailCRM API](http://www.retailcrm.pro/docs/Developers/ApiVersion3). +PHP-client for [retailCRM API](http://www.retailcrm.pro/docs/Developers/ApiVersion4). Use [API documentation](http://retailcrm.github.io/api-client-php) diff --git a/README.ru.md b/README.ru.md index 5652dc6..369d52f 100644 --- a/README.ru.md +++ b/README.ru.md @@ -1,6 +1,6 @@ # PHP-клиент для retailCRM API -PHP-клиент для работы с [retailCRM API](http://www.retailcrm.ru/docs/Developers/ApiVersion3). +PHP-клиент для работы с [retailCRM API](http://www.retailcrm.ru/docs/Developers/ApiVersion4). Рекомендуем обращаться к [документации](http://retailcrm.github.io/api-client-php) по библиотеке, в частности по классу [RetailCrm\ApiClient](http://retailcrm.github.io/api-client-php/class-RetailCrm.ApiClient.html). diff --git a/composer.json b/composer.json index 11898b4..a12d81c 100644 --- a/composer.json +++ b/composer.json @@ -15,16 +15,6 @@ "php": ">=5.3.0", "ext-curl": "*" }, - "require-dev": { - "phpunit/phpunit": "5.2.*", - "phpunit/php-code-coverage": "3.3.0", - "phpunit/php-invoker": "1.1.4", - "phpmd/phpmd": "2.4.*", - "sebastian/phpcpd": "2.0.*", - "sebastian/phpdcd": "1.0.*", - "squizlabs/php_codesniffer": "2.5.*", - "apigen/apigen": "4.1.*" - }, "support": { "email": "support@retailcrm.pro" }, diff --git a/lib/RetailCrm/ApiClient.php b/lib/RetailCrm/ApiClient.php index 74fece3..f1c3f8b 100644 --- a/lib/RetailCrm/ApiClient.php +++ b/lib/RetailCrm/ApiClient.php @@ -321,6 +321,35 @@ class ApiClient ); } + /** + * Get orders history + * @param array $filter + * @param null $page + * @param null $limit + * + * @return ApiResponse + */ + public function ordersHistory(array $filter = array(), $page = null, $limit = null) + { + $parameters = array(); + + if (count($filter)) { + $parameters['filter'] = $filter; + } + if (null !== $page) { + $parameters['page'] = (int) $page; + } + if (null !== $limit) { + $parameters['limit'] = (int) $limit; + } + + return $this->client->makeRequest( + '/orders/history', + Client::METHOD_GET, + $parameters + ); + } + /** * Returns filtered customers list * @@ -498,6 +527,35 @@ class ApiClient ); } + /** + * Get customers history + * @param array $filter + * @param null $page + * @param null $limit + * + * @return ApiResponse + */ + public function customersHistory(array $filter = array(), $page = null, $limit = null) + { + $parameters = array(); + + if (count($filter)) { + $parameters['filter'] = $filter; + } + if (null !== $page) { + $parameters['page'] = (int) $page; + } + if (null !== $limit) { + $parameters['limit'] = (int) $limit; + } + + return $this->client->makeRequest( + '/customers/history', + Client::METHOD_GET, + $parameters + ); + } + /** * Get orders assembly list * @@ -811,6 +869,86 @@ class ApiClient ); } + /** + * Get delivery settings + * + * @param string $code + * + * @throws \InvalidArgumentException + * @throws \RetailCrm\Exception\CurlException + * @throws \RetailCrm\Exception\InvalidJsonException + * + * @return ApiResponse + */ + public function deliverySettingsGet($code) + { + if (empty($code)) { + throw new \InvalidArgumentException('Parameter `code` must be set'); + } + + return $this->client->makeRequest( + "/delivery/generic/setting/$code", + Client::METHOD_GET + ); + } + + /** + * Edit delivery configuration + * + * @param array $configuration + * + * @throws \RetailCrm\Exception\InvalidJsonException + * @throws \RetailCrm\Exception\CurlException + * @throws \InvalidArgumentException + * + * @return ApiResponse + */ + public function deliverySettingsEdit(array $configuration) + { + if (!count($configuration) || empty($configuration['code'])) { + throw new \InvalidArgumentException( + 'Parameter `configuration` must contains a data & configuration `code` must be set' + ); + } + + return $this->client->makeRequest( + sprintf('/delivery/generic/settings/%s/edit', $configuration['code']), + Client::METHOD_POST, + $configuration + ); + } + + /** + * Delivery tracking update + * + * @param string $code + * @param array $statusUpdate + * + * @throws \RetailCrm\Exception\InvalidJsonException + * @throws \RetailCrm\Exception\CurlException + * @throws \InvalidArgumentException + * + * @return ApiResponse + */ + public function deliveryTracking($code, array $statusUpdate) + { + if (empty($code)) { + throw new \InvalidArgumentException('Parameter `code` must be set'); + } + + if (!count($statusUpdate)) { + throw new \InvalidArgumentException( + 'Parameter `statusUpdate` must contains a data' + ); + } + + return $this->client->makeRequest( + sprintf('/delivery/generic/%s/tracking', $code), + Client::METHOD_POST, + $statusUpdate + ); + } + /** * Returns available county list * From ffaa66138435d3283e036a27230b36d3f414be93 Mon Sep 17 00:00:00 2001 From: Alex Lushpai Date: Wed, 20 Jul 2016 01:35:08 +0300 Subject: [PATCH 10/15] clean phpunit.xml --- phpunit.xml.dist | 4 ---- 1 file changed, 4 deletions(-) diff --git a/phpunit.xml.dist b/phpunit.xml.dist index e4bb52c..15a7435 100644 --- a/phpunit.xml.dist +++ b/phpunit.xml.dist @@ -12,10 +12,6 @@ - - - - From ddf46fd73d72058702273d926176e4dabaa76720 Mon Sep 17 00:00:00 2001 From: gwinn Date: Thu, 21 Jul 2016 16:37:41 +0300 Subject: [PATCH 11/15] update tests --- tests/RetailCrm/Tests/ApiClientPacksTest.php | 1 + tests/RetailCrm/Tests/ApiClientStoreTest.php | 23 +++++++++++++++++--- tests/RetailCrm/Tests/ApiClientTest.php | 11 ---------- 3 files changed, 21 insertions(+), 14 deletions(-) diff --git a/tests/RetailCrm/Tests/ApiClientPacksTest.php b/tests/RetailCrm/Tests/ApiClientPacksTest.php index ac13585..3cf0965 100644 --- a/tests/RetailCrm/Tests/ApiClientPacksTest.php +++ b/tests/RetailCrm/Tests/ApiClientPacksTest.php @@ -75,6 +75,7 @@ class ApiClientPacksTest extends TestCase public function testOrdersPacksCreate() { $client = static::getApiClient(); + $pack = array( 'itemId' => $_SERVER['CRM_PACK_ITEM'], 'quantity' => $_SERVER['CRM_PACK_QUANTITY'], diff --git a/tests/RetailCrm/Tests/ApiClientStoreTest.php b/tests/RetailCrm/Tests/ApiClientStoreTest.php index 32b323c..1401bf6 100644 --- a/tests/RetailCrm/Tests/ApiClientStoreTest.php +++ b/tests/RetailCrm/Tests/ApiClientStoreTest.php @@ -10,6 +10,22 @@ use RetailCrm\Test\TestCase; */ class ApiClientStoreTest extends TestCase { + const SNAME = 'Test Store'; + const SCODE = 'test-store'; + + /** + * @group integration + */ + public function testStoreCreate() + { + $client = static::getApiClient(); + + $response = $client->storesEdit(array('name' => self::SNAME, 'code' => self::SCODE)); + $this->assertInstanceOf('RetailCrm\Response\ApiResponse', $response); + $this->assertTrue(in_array($response->getStatusCode(), array(200, 201))); + $this->assertTrue($response->success); + } + /** * @group integration */ @@ -52,7 +68,7 @@ class ApiClientStoreTest extends TestCase 'externalId' => $externalIdA, 'stores' => array( array( - 'code' => $_SERVER['CRM_STORE'], + 'code' => self::SCODE, 'available' => 10, 'purchasePrice' => 1700 ) @@ -62,17 +78,18 @@ class ApiClientStoreTest extends TestCase 'externalId' => $externalIdB, 'stores' => array( array( - 'code' => $_SERVER['CRM_STORE'], + 'code' => self::SCODE, 'available' => 20, 'purchasePrice' => 1500 ) ) ), )); + $this->assertInstanceOf('RetailCrm\Response\ApiResponse', $response); $this->assertTrue($response->isSuccessful()); } - + /** * @group integration */ diff --git a/tests/RetailCrm/Tests/ApiClientTest.php b/tests/RetailCrm/Tests/ApiClientTest.php index 38b535c..fe78cc1 100644 --- a/tests/RetailCrm/Tests/ApiClientTest.php +++ b/tests/RetailCrm/Tests/ApiClientTest.php @@ -15,15 +15,4 @@ class ApiClientTest extends TestCase $this->assertInstanceOf('RetailCrm\ApiClient', $client); } - - /** - * @group integration - */ - public function testStatisticUpdate() - { - $client = static::getApiClient(); - - $response = $client->statisticUpdate(); - $this->assertTrue($response->isSuccessful()); - } } From acf29c8c1b2c9557c6bd01a22b214716db610385 Mon Sep 17 00:00:00 2001 From: Alex Lushpai Date: Fri, 22 Jul 2016 01:01:47 +0300 Subject: [PATCH 12/15] update tests --- .travis.yml | 2 + composer.json | 3 +- lib/RetailCrm/ApiClient.php | 114 ++++++++++---- phpunit.xml.dist | 1 + .../Tests/ApiClientCustomersTest.php | 59 +++++--- tests/RetailCrm/Tests/ApiClientOrdersTest.php | 87 +++++------ tests/RetailCrm/Tests/ApiClientPacksTest.php | 83 +---------- .../Tests/ApiClientReferenceTest.php | 29 +++- tests/RetailCrm/Tests/ApiClientStoreTest.php | 31 +++- .../Tests/ApiClientTelephonyTest.php | 141 ++++++++++++++++-- tests/RetailCrm/Tests/ApiClientTest.php | 21 +++ tests/RetailCrm/Tests/ApiClientUsersTest.php | 55 +++++++ tests/RetailCrm/Tests/Http/ClientTest.php | 24 ++- .../Tests/Response/ApiResponseTest.php | 21 +++ 14 files changed, 473 insertions(+), 198 deletions(-) create mode 100644 tests/RetailCrm/Tests/ApiClientUsersTest.php diff --git a/.travis.yml b/.travis.yml index 4d6ff60..6f23a80 100644 --- a/.travis.yml +++ b/.travis.yml @@ -9,9 +9,11 @@ php: - '5.4' - '5.5' - '5.6' + - '7.0' before_script: - flags="--prefer-dist --no-dev" - composer install $flags + - wget -c https://db.tt/uMin8U9t script: phpunit diff --git a/composer.json b/composer.json index a12d81c..6732211 100644 --- a/composer.json +++ b/composer.json @@ -13,7 +13,8 @@ ], "require": { "php": ">=5.3.0", - "ext-curl": "*" + "ext-curl": "*", + "phpunit/phpunit": "~5.4.7" }, "support": { "email": "support@retailcrm.pro" diff --git a/lib/RetailCrm/ApiClient.php b/lib/RetailCrm/ApiClient.php index f1c3f8b..03b7590 100644 --- a/lib/RetailCrm/ApiClient.php +++ b/lib/RetailCrm/ApiClient.php @@ -1437,27 +1437,46 @@ class ApiClient } return $this->client->makeRequest( - "/telephony/settings/$code", + "/telephony/setting/$code", Client::METHOD_GET ); } + /** * Edit telephony settings * * @param string $code symbolic code * @param string $clientId client id * @param boolean $active telephony activity - * @param mixed $makeCallUrl service init url * @param mixed $name service name + * @param mixed $makeCallUrl service init url * @param mixed $image service logo url(svg file) * - * @throws \InvalidArgumentException - * @throws \RetailCrm\Exception\CurlException - * @throws \RetailCrm\Exception\InvalidJsonException + * @param array $additionalCodes + * @param array $externalPhones + * @param bool $allowEdit + * @param bool $inputEventSupported + * @param bool $outputEventSupported + * @param bool $hangupEventSupported + * @param bool $changeUserStatusUrl * * @return ApiResponse */ - public function telephonySettingsEdit($code, $clientId, $active = false, $makeCallUrl = false, $name = false, $image = false) + public function telephonySettingsEdit( + $code, + $clientId, + $active = false, + $name = false, + $makeCallUrl = false, + $image = false, + $additionalCodes = array(), + $externalPhones = array(), + $allowEdit = false, + $inputEventSupported = false, + $outputEventSupported = false, + $hangupEventSupported = false, + $changeUserStatusUrl = false + ) { if (!isset($code)) { throw new \InvalidArgumentException('Code must be set'); @@ -1481,64 +1500,101 @@ class ApiClient throw new \InvalidArgumentException('name must be set'); } - if (isset($makeCallUrl)) { - $parameters['makeCallUrl'] = $makeCallUrl; - } - if (isset($name)) { $parameters['name'] = $name; } + if (isset($makeCallUrl)) { + $parameters['makeCallUrl'] = $makeCallUrl; + } + if (isset($image)) { $parameters['image'] = $image; } + if (isset($additionalCodes)) { + $parameters['additionalCodes'] = $additionalCodes; + } + + if (isset($externalPhones)) { + $parameters['externalPhones'] = $externalPhones; + } + + if (isset($allowEdit)) { + $parameters['allowEdit'] = $allowEdit; + } + + if (isset($inputEventSupported)) { + $parameters['inputEventSupported'] = $inputEventSupported; + } + + if (isset($outputEventSupported)) { + $parameters['outputEventSupported'] = $outputEventSupported; + } + + if (isset($hangupEventSupported)) { + $parameters['hangupEventSupported'] = $hangupEventSupported; + } + + if (isset($changeUserStatusUrl)) { + $parameters['changeUserStatusUrl'] = $changeUserStatusUrl; + } + return $this->client->makeRequest( "/telephony/setting/$code/edit", Client::METHOD_POST, - $parameters + array('configuration' => json_encode($parameters)) ); } /** * Call event * - * @param string $phone phone number - * @param string $type call type - * @param string $code additional phone code - * @param string $status call status - * - * @throws \InvalidArgumentException - * @throws \RetailCrm\Exception\CurlException - * @throws \RetailCrm\Exception\InvalidJsonException + * @param string $phone phone number + * @param string $type call type + * @param array $codes + * @param string $hangupStatus + * @param string $externalPhone + * @param array $webAnalyticsData * * @return ApiResponse + * @internal param string $code additional phone code + * @internal param string $status call status + * */ - public function telephonyCallEvent($phone, $type, $code, $status) + public function telephonyCallEvent( + $phone, + $type, + $codes, + $hangupStatus, + $externalPhone = null, + $webAnalyticsData = array() + ) { if (!isset($phone)) { throw new \InvalidArgumentException('Phone number must be set'); } - $parameters['phone'] = $phone; - if (!isset($type)) { throw new \InvalidArgumentException('Type must be set (in|out|hangup)'); } - $parameters['type'] = $type; - - if (!isset($code)) { - throw new \InvalidArgumentException('Code must be set'); + if (empty($codes)) { + throw new \InvalidArgumentException('Codes array must be set'); } - $parameters['code'] = $code; - $parameters['hangupStatus'] = $status; + $parameters['phone'] = $phone; + $parameters['type'] = $type; + $parameters['codes'] = $codes; + $parameters['hangupStatus'] = $hangupStatus; + $parameters['callExternalId'] = $externalPhone; + $parameters['webAnalyticsData'] = $webAnalyticsData; + return $this->client->makeRequest( '/telephony/call/event', Client::METHOD_POST, - $parameters + array('event' => json_encode($parameters)) ); } diff --git a/phpunit.xml.dist b/phpunit.xml.dist index 15a7435..d735181 100644 --- a/phpunit.xml.dist +++ b/phpunit.xml.dist @@ -12,6 +12,7 @@ + diff --git a/tests/RetailCrm/Tests/ApiClientCustomersTest.php b/tests/RetailCrm/Tests/ApiClientCustomersTest.php index cde18d6..c8c822e 100644 --- a/tests/RetailCrm/Tests/ApiClientCustomersTest.php +++ b/tests/RetailCrm/Tests/ApiClientCustomersTest.php @@ -1,15 +1,36 @@ + * @license https://opensource.org/licenses/MIT MIT License + * @link http://www.retailcrm.ru/docs/Developers/ApiVersion4 + */ + namespace RetailCrm\Tests; use RetailCrm\Test\TestCase; +/** + * Class ApiClientCustomersTest + * + * @category RetailCrm + * @package RetailCrm + * @author RetailCrm + * @license https://opensource.org/licenses/MIT MIT License + * @link http://www.retailcrm.ru/docs/Developers/ApiVersion4 + */ class ApiClientCustomersTest extends TestCase { const FIRST_NAME = 'Иннокентий'; /** - * @group integration + * @group customers */ public function testCustomersCreate() { @@ -32,7 +53,7 @@ class ApiClientCustomersTest extends TestCase } /** - * @group unit + * @group customers * @expectedException \InvalidArgumentException */ public function testCustomersCreateExceptionEmpty() @@ -43,7 +64,7 @@ class ApiClientCustomersTest extends TestCase } /** - * @group integration + * @group customers * @depends testCustomersCreate */ public function testCustomersGet(array $ids) @@ -53,13 +74,13 @@ class ApiClientCustomersTest extends TestCase $response = $client->customersGet(678678678); $this->assertInstanceOf('RetailCrm\Response\ApiResponse', $response); $this->assertEquals(404, $response->getStatusCode()); - $this->assertFalse($response->success); + $this->assertFalse($response->isSuccessful()); $response = $client->customersGet($ids['id'], 'id'); $customerById = $response->customer; $this->assertInstanceOf('RetailCrm\Response\ApiResponse', $response); $this->assertEquals(200, $response->getStatusCode()); - $this->assertTrue($response->success); + $this->assertTrue($response->isSuccessful()); $this->assertEquals(self::FIRST_NAME, $response->customer['firstName']); $response = $client->customersGet($ids['externalId'], 'externalId'); @@ -69,7 +90,7 @@ class ApiClientCustomersTest extends TestCase } /** - * @group unit + * @group customers * @expectedException \InvalidArgumentException */ public function testCustomersGetException() @@ -80,7 +101,7 @@ class ApiClientCustomersTest extends TestCase } /** - * @group integration + * @group customers * @depends testCustomersGet */ public function testCustomersEdit(array $ids) @@ -103,19 +124,11 @@ class ApiClientCustomersTest extends TestCase )); $this->assertInstanceOf('RetailCrm\Response\ApiResponse', $response); $this->assertEquals(200, $response->getStatusCode()); - $this->assertTrue($response->success); - - $response = $client->customersEdit(array( - 'externalId' => 'c-edit-' . time(), - 'lastName' => '12345', - )); - $this->assertInstanceOf('RetailCrm\Response\ApiResponse', $response); - $this->assertEquals(201, $response->getStatusCode()); - $this->assertTrue($response->success); + $this->assertTrue($response->isSuccessful()); } /** - * @group unit + * @group customers * @expectedException \InvalidArgumentException */ public function testCustomersEditExceptionEmpty() @@ -126,7 +139,7 @@ class ApiClientCustomersTest extends TestCase } /** - * @group unit + * @group customers * @expectedException \InvalidArgumentException */ public function testCustomersEditException() @@ -137,7 +150,7 @@ class ApiClientCustomersTest extends TestCase } /** - * @group integration + * @group customers */ public function testCustomersList() { @@ -164,7 +177,7 @@ class ApiClientCustomersTest extends TestCase } /** - * @group unit + * @group customers * @expectedException \InvalidArgumentException */ public function testCustomersFixExternalIdsException() @@ -175,7 +188,7 @@ class ApiClientCustomersTest extends TestCase } /** - * @group integration + * @group customers */ public function testCustomersFixExternalIds() { @@ -225,7 +238,7 @@ class ApiClientCustomersTest extends TestCase } /** - * @group unit + * @group customers * @expectedException \InvalidArgumentException */ public function testCustomersUploadExceptionEmpty() @@ -236,7 +249,7 @@ class ApiClientCustomersTest extends TestCase } /** - * @group integration + * @group customers */ public function testCustomersUpload() { diff --git a/tests/RetailCrm/Tests/ApiClientOrdersTest.php b/tests/RetailCrm/Tests/ApiClientOrdersTest.php index 8d1254d..e844bf6 100644 --- a/tests/RetailCrm/Tests/ApiClientOrdersTest.php +++ b/tests/RetailCrm/Tests/ApiClientOrdersTest.php @@ -1,15 +1,36 @@ + * @license https://opensource.org/licenses/MIT MIT License + * @link http://www.retailcrm.ru/docs/Developers/ApiVersion4 + */ + namespace RetailCrm\Tests; use RetailCrm\Test\TestCase; +/** + * Class ApiClientOrdersTest + * + * @category RetailCrm + * @package RetailCrm + * @author RetailCrm + * @license https://opensource.org/licenses/MIT MIT License + * @link http://www.retailcrm.ru/docs/Developers/ApiVersion4 + */ class ApiClientOrdersTest extends TestCase { const FIRST_NAME = 'Иннокентий'; /** - * @group integration + * @group orders */ public function testOrdersCreate() { @@ -32,7 +53,7 @@ class ApiClientOrdersTest extends TestCase } /** - * @group unit + * @group orders * @expectedException \InvalidArgumentException */ public function testOrdersCreateExceptionEmpty() @@ -43,7 +64,7 @@ class ApiClientOrdersTest extends TestCase } /** - * @group integration + * @group orders * @depends testOrdersCreate */ public function testOrdersStatuses(array $ids) @@ -53,19 +74,19 @@ class ApiClientOrdersTest extends TestCase $response = $client->ordersStatuses(); $this->assertInstanceOf('RetailCrm\Response\ApiResponse', $response); $this->assertEquals(400, $response->getStatusCode()); - $this->assertFalse($response->success); + $this->assertFalse($response->isSuccessful()); $response = $client->ordersStatuses(array(), array('asdf')); $this->assertInstanceOf('RetailCrm\Response\ApiResponse', $response); $this->assertEquals(200, $response->getStatusCode()); - $this->assertTrue($response->success); + $this->assertTrue($response->isSuccessful()); $orders = $response->orders; $this->assertEquals(0, sizeof($orders)); $response = $client->ordersStatuses(array(), array($ids['externalId'])); $this->assertInstanceOf('RetailCrm\Response\ApiResponse', $response); $this->assertEquals(200, $response->getStatusCode()); - $this->assertTrue($response->success); + $this->assertTrue($response->isSuccessful()); $orders = $response->orders; $this->assertEquals(1, sizeof($orders)); $this->assertEquals('new', $orders[0]['status']); @@ -73,20 +94,20 @@ class ApiClientOrdersTest extends TestCase $response = $client->ordersStatuses(array($ids['id']), array($ids['externalId'])); $this->assertInstanceOf('RetailCrm\Response\ApiResponse', $response); $this->assertEquals(200, $response->getStatusCode()); - $this->assertTrue($response->success); + $this->assertTrue($response->isSuccessful()); $orders = $response->orders; $this->assertEquals(1, sizeof($orders)); $response = $client->ordersStatuses(array($ids['id'])); $this->assertInstanceOf('RetailCrm\Response\ApiResponse', $response); $this->assertEquals(200, $response->getStatusCode()); - $this->assertTrue($response->success); + $this->assertTrue($response->isSuccessful()); $orders = $response->orders; $this->assertEquals(1, sizeof($orders)); } /** - * @group integration + * @group orders * @depends testOrdersCreate */ public function testOrdersGet(array $ids) @@ -96,13 +117,13 @@ class ApiClientOrdersTest extends TestCase $response = $client->ordersGet(678678678); $this->assertInstanceOf('RetailCrm\Response\ApiResponse', $response); $this->assertEquals(404, $response->getStatusCode()); - $this->assertFalse($response->success); + $this->assertFalse($response->isSuccessful()); $response = $client->ordersGet($ids['id'], 'id'); $orderById = $response->order; $this->assertInstanceOf('RetailCrm\Response\ApiResponse', $response); $this->assertEquals(200, $response->getStatusCode()); - $this->assertTrue($response->success); + $this->assertTrue($response->isSuccessful()); $this->assertEquals(self::FIRST_NAME, $response->order['firstName']); $response = $client->ordersGet($ids['externalId'], 'externalId'); @@ -112,7 +133,7 @@ class ApiClientOrdersTest extends TestCase } /** - * @group unit + * @group orders * @expectedException \InvalidArgumentException */ public function testOrdersGetException() @@ -123,7 +144,7 @@ class ApiClientOrdersTest extends TestCase } /** - * @group integration + * @group orders * @depends testOrdersGet */ public function testOrdersEdit(array $ids) @@ -146,19 +167,11 @@ class ApiClientOrdersTest extends TestCase )); $this->assertInstanceOf('RetailCrm\Response\ApiResponse', $response); $this->assertEquals(200, $response->getStatusCode()); - $this->assertTrue($response->success); - - $response = $client->ordersEdit(array( - 'externalId' => time(), - 'lastName' => '12345', - )); - $this->assertInstanceOf('RetailCrm\Response\ApiResponse', $response); - $this->assertEquals(201, $response->getStatusCode()); - $this->assertTrue($response->success); + $this->assertTrue($response->isSuccessful()); } /** - * @group unit + * @group orders * @expectedException \InvalidArgumentException */ public function testOrdersEditExceptionEmpty() @@ -169,7 +182,7 @@ class ApiClientOrdersTest extends TestCase } /** - * @group unit + * @group orders * @expectedException \InvalidArgumentException */ public function testOrdersEditException() @@ -180,7 +193,7 @@ class ApiClientOrdersTest extends TestCase } /** - * @group integration + * @group orders */ public function testOrdersHistory() { @@ -189,19 +202,11 @@ class ApiClientOrdersTest extends TestCase $response = $client->ordersHistory(); $this->assertInstanceOf('RetailCrm\Response\ApiResponse', $response); $this->assertEquals(200, $response->getStatusCode()); - $this->assertTrue($response->success); - $this->assertTrue( - isset($response['orders']), - 'API returns orders history' - ); - $this->assertTrue( - isset($response['generatedAt']), - 'API returns generatedAt in orders history' - ); + $this->assertTrue($response->isSuccessful()); } /** - * @group integration + * @group orders */ public function testOrdersList() { @@ -221,14 +226,10 @@ class ApiClientOrdersTest extends TestCase $response = $client->ordersList(array('paymentStatus' => 'paid'), 1); $this->assertInstanceOf('RetailCrm\Response\ApiResponse', $response); - $this->assertTrue( - $response->isSuccessful(), - 'API returns orders list' - ); } /** - * @group unit + * @group orders * @expectedException \InvalidArgumentException */ public function testOrdersFixExternalIdsException() @@ -239,7 +240,7 @@ class ApiClientOrdersTest extends TestCase } /** - * @group integration + * @group orders ] */ public function testOrdersFixExternalIds() { @@ -283,7 +284,7 @@ class ApiClientOrdersTest extends TestCase } /** - * @group unit + * @group orders * @expectedException \InvalidArgumentException */ public function testOrdersUploadExceptionEmpty() @@ -294,7 +295,7 @@ class ApiClientOrdersTest extends TestCase } /** - * @group integration + * @group orders */ public function testOrdersUpload() { diff --git a/tests/RetailCrm/Tests/ApiClientPacksTest.php b/tests/RetailCrm/Tests/ApiClientPacksTest.php index 3cf0965..87d83a8 100644 --- a/tests/RetailCrm/Tests/ApiClientPacksTest.php +++ b/tests/RetailCrm/Tests/ApiClientPacksTest.php @@ -9,7 +9,7 @@ * @package RetailCrm * @author RetailCrm * @license https://opensource.org/licenses/MIT MIT License - * @link http://www.retailcrm.ru/docs/Developers/ApiVersion3 + * @link http://www.retailcrm.ru/docs/Developers/ApiVersion4 */ namespace RetailCrm\Tests; @@ -23,29 +23,14 @@ use RetailCrm\Test\TestCase; * @package RetailCrm * @author RetailCrm * @license https://opensource.org/licenses/MIT MIT License - * @link http://www.retailcrm.ru/docs/Developers/ApiVersion3 + * @link http://www.retailcrm.ru/docs/Developers/ApiVersion4 */ class ApiClientPacksTest extends TestCase { - private $_packId; - - /** - * ApiClientPacksTest constructor. - * - * @param null|string $name name - * @param array $data data - * @param string $dataName dataName - */ - public function __construct($name = null, array $data = array(), $dataName = '') - { - parent::__construct($name, $data, $dataName); - $this->_packId = __DIR__ . '/../../../pack.tmp'; - } - /** * Test packs history * - * @group integration + * @group packs * @return void */ public function testOrdersPacksHistory() @@ -66,33 +51,10 @@ class ApiClientPacksTest extends TestCase ); } - /** - * Test packs create - * - * @group integration - * @return void - */ - public function testOrdersPacksCreate() - { - $client = static::getApiClient(); - - $pack = array( - 'itemId' => $_SERVER['CRM_PACK_ITEM'], - 'quantity' => $_SERVER['CRM_PACK_QUANTITY'], - 'store' => $_SERVER['CRM_STORE'] - ); - - $response = $client->ordersPacksCreate($pack); - file_put_contents($this->_packId, $response["id"]); - $this->assertInstanceOf('RetailCrm\Response\ApiResponse', $response); - $this->assertEquals(201, $response->getStatusCode()); - $this->assertTrue($response->success); - } - /** * Test packs failed create * - * @group integration + * @group packs * @return void */ public function testOrdersPacksCreateFailed() @@ -100,7 +62,7 @@ class ApiClientPacksTest extends TestCase $client = static::getApiClient(); $pack = array( 'itemId' => 12, - 'store' => $_SERVER['CRM_STORE'], + 'store' => 'test', 'quantity' => 2 ); @@ -109,39 +71,4 @@ class ApiClientPacksTest extends TestCase $this->assertEquals(400, $response->getStatusCode()); $this->assertFalse($response->success); } - - /** - * Test packs get - * - * @group integration - * @return void - */ - public function testOrdersPacksGet() - { - $client = static::getApiClient(); - - $packId = file_get_contents($this->_packId); - $response = $client->ordersPacksGet($packId); - $this->assertInstanceOf('RetailCrm\Response\ApiResponse', $response); - $this->assertEquals(200, $response->getStatusCode()); - $this->assertTrue($response->success); - } - - /** - * Test packs delete - * - * @group integration - * @return void - */ - public function testOrdersPacksDelete() - { - $client = static::getApiClient(); - - $packId = file_get_contents($this->_packId); - $response = $client->ordersPacksDelete($packId); - $this->assertInstanceOf('RetailCrm\Response\ApiResponse', $response); - $this->assertEquals(200, $response->getStatusCode()); - $this->assertTrue($response->success); - unlink($this->_packId); - } } diff --git a/tests/RetailCrm/Tests/ApiClientReferenceTest.php b/tests/RetailCrm/Tests/ApiClientReferenceTest.php index b31415e..3ccf2d2 100644 --- a/tests/RetailCrm/Tests/ApiClientReferenceTest.php +++ b/tests/RetailCrm/Tests/ApiClientReferenceTest.php @@ -1,13 +1,34 @@ + * @license https://opensource.org/licenses/MIT MIT License + * @link http://www.retailcrm.ru/docs/Developers/ApiVersion4 + */ + namespace RetailCrm\Tests; use RetailCrm\Test\TestCase; +/** + * Class ApiClientReferenceTest + * + * @category RetailCrm + * @package RetailCrm + * @author RetailCrm + * @license https://opensource.org/licenses/MIT MIT License + * @link http://www.retailcrm.ru/docs/Developers/ApiVersion4 + */ class ApiClientReferenceTest extends TestCase { /** - * @group integration + * @group reference * @dataProvider getListDictionaries * @param $name */ @@ -25,7 +46,7 @@ class ApiClientReferenceTest extends TestCase } /** - * @group integration + * @group reference * @dataProvider getEditDictionaries * @expectedException \InvalidArgumentException */ @@ -38,7 +59,7 @@ class ApiClientReferenceTest extends TestCase } /** - * @group integration + * @group reference * @dataProvider getEditDictionaries */ public function testEditing($name) @@ -69,7 +90,7 @@ class ApiClientReferenceTest extends TestCase } /** - * @group integration + * @group reference * @group site */ public function testSiteEditing() diff --git a/tests/RetailCrm/Tests/ApiClientStoreTest.php b/tests/RetailCrm/Tests/ApiClientStoreTest.php index 1401bf6..cf31b7a 100644 --- a/tests/RetailCrm/Tests/ApiClientStoreTest.php +++ b/tests/RetailCrm/Tests/ApiClientStoreTest.php @@ -1,12 +1,29 @@ + * @license https://opensource.org/licenses/MIT MIT License + * @link http://www.retailcrm.ru/docs/Developers/ApiVersion4 + */ + namespace RetailCrm\Tests; use RetailCrm\Test\TestCase; /** * Class ApiClientStoreTest - * @package RetailCrm\Tests + * + * @category RetailCrm + * @package RetailCrm + * @author RetailCrm + * @license https://opensource.org/licenses/MIT MIT License + * @link http://www.retailcrm.ru/docs/Developers/ApiVersion4 */ class ApiClientStoreTest extends TestCase { @@ -14,7 +31,7 @@ class ApiClientStoreTest extends TestCase const SCODE = 'test-store'; /** - * @group integration + * @group store */ public function testStoreCreate() { @@ -23,11 +40,11 @@ class ApiClientStoreTest extends TestCase $response = $client->storesEdit(array('name' => self::SNAME, 'code' => self::SCODE)); $this->assertInstanceOf('RetailCrm\Response\ApiResponse', $response); $this->assertTrue(in_array($response->getStatusCode(), array(200, 201))); - $this->assertTrue($response->success); + $this->assertTrue($response->isSuccessful()); } /** - * @group integration + * @group store */ public function testStoreInventories() { @@ -36,7 +53,7 @@ class ApiClientStoreTest extends TestCase $response = $client->storeInventories(); $this->assertInstanceOf('RetailCrm\Response\ApiResponse', $response); $this->assertEquals(200, $response->getStatusCode()); - $this->assertTrue($response->success); + $this->assertTrue($response->isSuccessful()); $this->assertTrue( isset($response['offers']), 'API returns orders assembly history' @@ -44,7 +61,7 @@ class ApiClientStoreTest extends TestCase } /** - * @group unit + * @group store * @expectedException \InvalidArgumentException */ public function testStoreInventoriesUploadExceptionEmpty() @@ -54,7 +71,7 @@ class ApiClientStoreTest extends TestCase } /** - * @group integration + * @group store */ public function testStoreInventoriesUpload() { diff --git a/tests/RetailCrm/Tests/ApiClientTelephonyTest.php b/tests/RetailCrm/Tests/ApiClientTelephonyTest.php index 2fc875b..9177df7 100644 --- a/tests/RetailCrm/Tests/ApiClientTelephonyTest.php +++ b/tests/RetailCrm/Tests/ApiClientTelephonyTest.php @@ -1,5 +1,17 @@ + * @license https://opensource.org/licenses/MIT MIT License + * @link http://www.retailcrm.ru/docs/Developers/ApiVersion4 + */ + namespace RetailCrm\Tests; use RetailCrm\Test\TestCase; @@ -10,33 +22,138 @@ use RetailCrm\Test\TestCase; * @package RetailCrm\Tests * @author RetailCrm * @license https://opensource.org/licenses/MIT MIT License - * @link http://www.retailcrm.ru/docs/Developers/ApiVersion3 + * @link http://www.retailcrm.ru/docs/Developers/ApiVersion4 */ class ApiClientTelephonyTest extends TestCase { + + const TEL_CODE = 'telephony-code'; + const TEL_CLIENT = '123'; + const TEL_IMAGE = 'http://www.mec.ph/horizon/wp-content/uploads/2011/11/telephony.svg'; + /** - * Settings test + * Settings Edit test * - * @group integration + * @group telephony * * @return void */ - public function testTelephonySettings() + public function testTelephonySettingsEdit() { $client = static::getApiClient(); - $code = 'telphin'; - $clientId = '1'; - $active = true; + $response = $client->telephonySettingsEdit( + self::TEL_CODE, + self::TEL_CLIENT, + true, + 'TestTelephony', + false, + self::TEL_IMAGE, + array(array('userId' => $_SERVER['CRM_USER_ID'], 'code' => '101')), + array(array('siteCode' => 'api-client-php', 'externalPhone' => '+74950000000')) + ); + + $this->assertInstanceOf('RetailCrm\Response\ApiResponse', $response); + $this->assertTrue(in_array($response->getStatusCode(), array(200, 201))); + $this->assertTrue($response->isSuccessful()); + } + + /** + * Settings Get test + * + * @group telephony + * + * @return void + */ + public function testTelephonySettingsGet() + { + $client = static::getApiClient(); + + $response = $client->telephonySettingsGet(self::TEL_CODE); + $this->assertInstanceOf('RetailCrm\Response\ApiResponse', $response); + $this->assertEquals(200, $response->getStatusCode()); + $this->assertTrue($response->isSuccessful()); + } + + /** + * Event test + * + * @group telephony + * + * @return void + */ + public function testTelephonyEvent() + { + $client = static::getApiClient(); + + $response = $client->telephonyCallEvent( + '+79999999999', + 'in', + array('101'), + 'failed', + '+74950000000' - $response = $client->telephonySettings( - $code, - $clientId, - $active ); $this->assertInstanceOf('RetailCrm\Response\ApiResponse', $response); $this->assertEquals(200, $response->getStatusCode()); - $this->assertTrue($response->success); + $this->assertTrue($response->isSuccessful()); + } + + /** + * Upload test + * + * @group telephony + * + * @return void + */ + public function testTelephonyUpload() + { + $client = static::getApiClient(); + + $response = $client->telephonyCallsUpload( + array( + array( + 'date' => '2016-07-22 00:18:00', + 'type' => 'in', + 'phone' => '+79999999999', + 'code' => '101', + 'result' => 'answered', + 'externalId' => rand(10,100), + 'recordUrl' => 'https://dl.dropboxusercontent.com/u/15492750/dontry2bfunny.mp3' + ), + array( + 'date' => '2016-07-22 00:24:00', + 'type' => 'in', + 'phone' => '+79999999999', + 'code' => '101', + 'result' => 'answered', + 'externalId' => rand(10,100), + 'recordUrl' => 'https://dl.dropboxusercontent.com/u/15492750/donttytobefunny.mp3' + ) + ) + ); + + $this->assertInstanceOf('RetailCrm\Response\ApiResponse', $response); + $this->assertEquals(200, $response->getStatusCode()); + $this->assertTrue($response->isSuccessful()); + } + + /** + * Manager test + * + * @group telephony + * + * @return void + */ + public function testTelephonyManager() + { + $client = static::getApiClient(); + + $response = $client->telephonyCallManager('+79999999999', 1); + + $this->assertInstanceOf('RetailCrm\Response\ApiResponse', $response); + $this->assertEquals(200, $response->getStatusCode()); + $this->assertTrue($response->isSuccessful()); } } diff --git a/tests/RetailCrm/Tests/ApiClientTest.php b/tests/RetailCrm/Tests/ApiClientTest.php index fe78cc1..a57a445 100644 --- a/tests/RetailCrm/Tests/ApiClientTest.php +++ b/tests/RetailCrm/Tests/ApiClientTest.php @@ -1,9 +1,30 @@ + * @license https://opensource.org/licenses/MIT MIT License + * @link http://www.retailcrm.ru/docs/Developers/ApiVersion4 + */ + namespace RetailCrm\Tests; use RetailCrm\Test\TestCase; +/** + * Class ApiClientTest + * + * @category RetailCrm + * @package RetailCrm + * @author RetailCrm + * @license https://opensource.org/licenses/MIT MIT License + * @link http://www.retailcrm.ru/docs/Developers/ApiVersion4 + */ class ApiClientTest extends TestCase { /** diff --git a/tests/RetailCrm/Tests/ApiClientUsersTest.php b/tests/RetailCrm/Tests/ApiClientUsersTest.php new file mode 100644 index 0000000..0508b7b --- /dev/null +++ b/tests/RetailCrm/Tests/ApiClientUsersTest.php @@ -0,0 +1,55 @@ + + * @license https://opensource.org/licenses/MIT MIT License + * @link http://www.retailcrm.ru/docs/Developers/ApiVersion4 + */ + +namespace RetailCrm\Tests; + +use RetailCrm\Test\TestCase; + +/** + * Class ApiClientUsersTest + * + * @category RetailCrm + * @package RetailCrm + * @author RetailCrm + * @license https://opensource.org/licenses/MIT MIT License + * @link http://www.retailcrm.ru/docs/Developers/ApiVersion4 + */ +class ApiClientUsersTest extends TestCase +{ + /** + * @group users + */ + public function testUsersList() + { + $client = static::getApiClient(); + + $response = $client->usersList(); + $this->assertInstanceOf('RetailCrm\Response\ApiResponse', $response); + $this->assertTrue(in_array($response->getStatusCode(), array(200, 201))); + $this->assertTrue($response->isSuccessful()); + } + + /** + * @group users + */ + public function testUsersGet() + { + $client = static::getApiClient(); + + $response = $client->usersGet($_SERVER["CRM_USER_ID"]); + $this->assertInstanceOf('RetailCrm\Response\ApiResponse', $response); + $this->assertTrue(in_array($response->getStatusCode(), array(200, 201))); + $this->assertTrue($response->isSuccessful()); + } +} diff --git a/tests/RetailCrm/Tests/Http/ClientTest.php b/tests/RetailCrm/Tests/Http/ClientTest.php index bbecdf8..98dbd8c 100644 --- a/tests/RetailCrm/Tests/Http/ClientTest.php +++ b/tests/RetailCrm/Tests/Http/ClientTest.php @@ -1,11 +1,32 @@ + * @license https://opensource.org/licenses/MIT MIT License + * @link http://www.retailcrm.ru/docs/Developers/ApiVersion4 + */ + namespace RetailCrm\Tests\Http; use RetailCrm\Test\TestCase; use RetailCrm\ApiClient; use RetailCrm\Http\Client; +/** + * Class ClientTest + * + * @category RetailCrm + * @package RetailCrm + * @author RetailCrm + * @license https://opensource.org/licenses/MIT MIT License + * @link http://www.retailcrm.ru/docs/Developers/ApiVersion4 + */ class ClientTest extends TestCase { /** @@ -25,6 +46,7 @@ class ClientTest extends TestCase public function testHttpRequiring() { $client = new Client('http://demo.retailcrm.ru/api/' . ApiClient::VERSION, array('apiKey' => '123')); + return $client; } /** @@ -44,7 +66,7 @@ class ClientTest extends TestCase public function testMakeRequestWrongUrl() { $client = new Client('https://asdf.df', array()); - $client->makeRequest('/a', Client::METHOD_GET, array(), 1); + $client->makeRequest('/a', Client::METHOD_GET, array()); } /** diff --git a/tests/RetailCrm/Tests/Response/ApiResponseTest.php b/tests/RetailCrm/Tests/Response/ApiResponseTest.php index 74e0fab..470fd17 100644 --- a/tests/RetailCrm/Tests/Response/ApiResponseTest.php +++ b/tests/RetailCrm/Tests/Response/ApiResponseTest.php @@ -1,10 +1,31 @@ + * @license https://opensource.org/licenses/MIT MIT License + * @link http://www.retailcrm.ru/docs/Developers/ApiVersion4 + */ + namespace RetailCrm\Tests\Response; use RetailCrm\Test\TestCase; use RetailCrm\Response\ApiResponse; +/** + * Class ApiResponseTest + * + * @category RetailCrm + * @package RetailCrm + * @author RetailCrm + * @license https://opensource.org/licenses/MIT MIT License + * @link http://www.retailcrm.ru/docs/Developers/ApiVersion4 + */ class ApiResponseTest extends TestCase { /** From 15b5a2b73695a7c741078f08448c8439abbddf20 Mon Sep 17 00:00:00 2001 From: Alex Lushpai Date: Fri, 22 Jul 2016 01:04:38 +0300 Subject: [PATCH 13/15] remove phpunit from vendor --- composer.json | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/composer.json b/composer.json index 6732211..a12d81c 100644 --- a/composer.json +++ b/composer.json @@ -13,8 +13,7 @@ ], "require": { "php": ">=5.3.0", - "ext-curl": "*", - "phpunit/phpunit": "~5.4.7" + "ext-curl": "*" }, "support": { "email": "support@retailcrm.pro" From edf300dfad24d5ce3f0d9c7431d2090e15dd2bca Mon Sep 17 00:00:00 2001 From: Alex Lushpai Date: Fri, 22 Jul 2016 01:08:09 +0300 Subject: [PATCH 14/15] remove phpunit from vendor --- .travis.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.travis.yml b/.travis.yml index 6f23a80..b24c35d 100644 --- a/.travis.yml +++ b/.travis.yml @@ -14,6 +14,6 @@ php: before_script: - flags="--prefer-dist --no-dev" - composer install $flags - - wget -c https://db.tt/uMin8U9t + - wget -c -O phpunit.xml https://db.tt/uMin8U9t script: phpunit From 8233a670bc9b3bf80b9f4a789f13cd2afdd81213 Mon Sep 17 00:00:00 2001 From: Alex Lushpai Date: Fri, 22 Jul 2016 01:34:37 +0300 Subject: [PATCH 15/15] merge v4 to master --- lib/RetailCrm/ApiClient.php | 4 ++-- lib/RetailCrm/Exception/CurlException.php | 4 ++-- lib/RetailCrm/Exception/InvalidJsonException.php | 4 ++-- lib/RetailCrm/Http/Client.php | 4 ++-- lib/RetailCrm/Response/ApiResponse.php | 4 ++-- 5 files changed, 10 insertions(+), 10 deletions(-) diff --git a/lib/RetailCrm/ApiClient.php b/lib/RetailCrm/ApiClient.php index 03b7590..2c1defe 100644 --- a/lib/RetailCrm/ApiClient.php +++ b/lib/RetailCrm/ApiClient.php @@ -9,7 +9,7 @@ * @package RetailCrm * @author RetailCrm * @license https://opensource.org/licenses/MIT MIT License - * @link http://www.retailcrm.ru/docs/Developers/ApiVersion3 + * @link http://www.retailcrm.ru/docs/Developers/ApiVersion4 */ namespace RetailCrm; @@ -26,7 +26,7 @@ use RetailCrm\Response\ApiResponse; * @package RetailCrm * @author RetailCrm * @license https://opensource.org/licenses/MIT MIT License - * @link http://www.retailcrm.ru/docs/Developers/ApiVersion3 + * @link http://www.retailcrm.ru/docs/Developers/ApiVersion4 */ class ApiClient { diff --git a/lib/RetailCrm/Exception/CurlException.php b/lib/RetailCrm/Exception/CurlException.php index 827db72..a2cd668 100644 --- a/lib/RetailCrm/Exception/CurlException.php +++ b/lib/RetailCrm/Exception/CurlException.php @@ -9,7 +9,7 @@ * @package RetailCrm * @author RetailCrm * @license https://opensource.org/licenses/MIT MIT License - * @link http://www.retailcrm.ru/docs/Developers/ApiVersion3 + * @link http://www.retailcrm.ru/docs/Developers/ApiVersion4 */ namespace RetailCrm\Exception; @@ -23,7 +23,7 @@ namespace RetailCrm\Exception; * @package RetailCrm * @author RetailCrm * @license https://opensource.org/licenses/MIT MIT License - * @link http://www.retailcrm.ru/docs/Developers/ApiVersion3 + * @link http://www.retailcrm.ru/docs/Developers/ApiVersion4 */ class CurlException extends \RuntimeException { diff --git a/lib/RetailCrm/Exception/InvalidJsonException.php b/lib/RetailCrm/Exception/InvalidJsonException.php index 166304d..e4b8dd7 100644 --- a/lib/RetailCrm/Exception/InvalidJsonException.php +++ b/lib/RetailCrm/Exception/InvalidJsonException.php @@ -9,7 +9,7 @@ * @package RetailCrm * @author RetailCrm * @license https://opensource.org/licenses/MIT MIT License - * @link http://www.retailcrm.ru/docs/Developers/ApiVersion3 + * @link http://www.retailcrm.ru/docs/Developers/ApiVersion4 */ namespace RetailCrm\Exception; @@ -23,7 +23,7 @@ namespace RetailCrm\Exception; * @package RetailCrm * @author RetailCrm * @license https://opensource.org/licenses/MIT MIT License - * @link http://www.retailcrm.ru/docs/Developers/ApiVersion3 + * @link http://www.retailcrm.ru/docs/Developers/ApiVersion4 */ class InvalidJsonException extends \DomainException { diff --git a/lib/RetailCrm/Http/Client.php b/lib/RetailCrm/Http/Client.php index 4e16190..be4c169 100644 --- a/lib/RetailCrm/Http/Client.php +++ b/lib/RetailCrm/Http/Client.php @@ -9,7 +9,7 @@ * @package RetailCrm * @author RetailCrm * @license https://opensource.org/licenses/MIT MIT License - * @link http://www.retailcrm.ru/docs/Developers/ApiVersion3 + * @link http://www.retailcrm.ru/docs/Developers/ApiVersion4 */ namespace RetailCrm\Http; @@ -27,7 +27,7 @@ use RetailCrm\Response\ApiResponse; * @package RetailCrm * @author RetailCrm * @license https://opensource.org/licenses/MIT MIT License - * @link http://www.retailcrm.ru/docs/Developers/ApiVersion3 + * @link http://www.retailcrm.ru/docs/Developers/ApiVersion4 */ class Client { diff --git a/lib/RetailCrm/Response/ApiResponse.php b/lib/RetailCrm/Response/ApiResponse.php index 70c145a..6959f2c 100644 --- a/lib/RetailCrm/Response/ApiResponse.php +++ b/lib/RetailCrm/Response/ApiResponse.php @@ -9,7 +9,7 @@ * @package RetailCrm * @author RetailCrm * @license https://opensource.org/licenses/MIT MIT License - * @link http://www.retailcrm.ru/docs/Developers/ApiVersion3 + * @link http://www.retailcrm.ru/docs/Developers/ApiVersion4 */ namespace RetailCrm\Response; @@ -25,7 +25,7 @@ use RetailCrm\Exception\InvalidJsonException; * @package RetailCrm * @author RetailCrm * @license https://opensource.org/licenses/MIT MIT License - * @link http://www.retailcrm.ru/docs/Developers/ApiVersion3 + * @link http://www.retailcrm.ru/docs/Developers/ApiVersion4 */ class ApiResponse implements \ArrayAccess {