1
0
Fork 0
mirror of synced 2025-04-11 13:10:57 +00:00

update test, fix minor bugs

This commit is contained in:
Alex Lushpai 2017-06-18 03:35:41 +03:00
parent a156fa0bcc
commit 68a2ff4ba0
54 changed files with 1932 additions and 494 deletions

View file

@ -17,8 +17,6 @@ namespace RetailCrm;
use RetailCrm\Client\ApiVersion3;
use RetailCrm\Client\ApiVersion4;
use RetailCrm\Client\ApiVersion5;
use RetailCrm\Methods\Core;
use RetailCrm\Methods\Statistic;
/**
* PHP version 5.4
@ -34,6 +32,7 @@ use RetailCrm\Methods\Statistic;
class ApiClient
{
public $request;
public $version;
/**
* Init version based client
@ -46,6 +45,8 @@ class ApiClient
*/
public function __construct($url, $apiKey, $version = 'v5', $site = null)
{
$this->version = $version;
switch ($version) {
case 'v5':
$this->request = new ApiVersion5($url, $apiKey, $version, $site);
@ -59,6 +60,13 @@ class ApiClient
}
}
use Core;
use Statistic;
/**
* Get API version
*
* @return string
*/
public function getVersion()
{
return $this->version;
}
}

View file

@ -57,4 +57,76 @@ abstract class AbstractLoader
$this->client = new Client($url, ['apiKey' => $apiKey]);
$this->siteCode = $site;
}
/**
* Set site
*
* @param string $site site code
*
* @return void
*/
public function setSite($site)
{
$this->siteCode = $site;
}
/**
* Check ID parameter
*
* @param string $by identify by
*
* @throws \InvalidArgumentException
*
* @return bool
*/
protected function checkIdParameter($by)
{
$allowedForBy = [
'externalId',
'id'
];
if (!in_array($by, $allowedForBy, false)) {
throw new \InvalidArgumentException(
sprintf(
'Value "%s" for "by" param is not valid. Allowed values are %s.',
$by,
implode(', ', $allowedForBy)
)
);
}
return true;
}
/**
* Fill params by site value
*
* @param string $site site code
* @param array $params input parameters
*
* @return array
*/
protected function fillSite($site, array $params)
{
if ($site) {
$params['site'] = $site;
} elseif ($this->siteCode) {
$params['site'] = $this->siteCode;
}
return $params;
}
/**
* Return current site
*
* @return string
*/
public function getSite()
{
return $this->siteCode;
}
}

View file

@ -47,6 +47,7 @@ class ApiVersion3 extends AbstractLoader
use V3\Orders;
use V3\Packs;
use V3\References;
use V3\Statistic;
use V3\Stores;
use V3\Telephony;
}

View file

@ -49,6 +49,7 @@ class ApiVersion4 extends AbstractLoader
use V4\Orders;
use V4\Packs;
use V4\References;
use V4\Statistic;
use V4\Stores;
use V4\Telephony;
use V4\Users;

View file

@ -51,6 +51,7 @@ class ApiVersion5 extends AbstractLoader
use V5\Packs;
use V5\References;
use V5\Segments;
use V5\Statistic;
use V5\Stores;
use V5\Tasks;
use V5\Telephony;

View file

@ -1,99 +0,0 @@
<?php
/**
* PHP version 5.4
*
* Core class
*
* @category RetailCrm
* @package RetailCrm
* @author RetailCrm <integration@retailcrm.ru>
* @license https://opensource.org/licenses/MIT MIT License
* @link http://www.retailcrm.ru/docs/Developers/ApiVersion5
*/
namespace RetailCrm\Methods;
/**
* PHP version 5.4
*
* Core class
*
* @category RetailCrm
* @package RetailCrm
* @author RetailCrm <integration@retailcrm.ru>
* @license https://opensource.org/licenses/MIT MIT License
* @link http://www.retailcrm.ru/docs/Developers/ApiVersion5
*/
trait Core
{
/**
* Return current site
*
* @return string
*/
public function getSite()
{
return $this->siteCode;
}
/**
* Set site
*
* @param string $site site code
*
* @return void
*/
public function setSite($site)
{
$this->siteCode = $site;
}
/**
* Check ID parameter
*
* @param string $by identify by
*
* @throws \InvalidArgumentException
*
* @return bool
*/
protected function checkIdParameter($by)
{
$allowedForBy = [
'externalId',
'id'
];
if (!in_array($by, $allowedForBy, false)) {
throw new \InvalidArgumentException(
sprintf(
'Value "%s" for "by" param is not valid. Allowed values are %s.',
$by,
implode(', ', $allowedForBy)
)
);
}
return true;
}
/**
* Fill params by site value
*
* @param string $site site code
* @param array $params input parameters
*
* @return array
*/
protected function fillSite($site, array $params)
{
if ($site) {
$params['site'] = $site;
} elseif ($this->siteCode) {
$params['site'] = $this->siteCode;
}
return $params;
}
}

View file

@ -38,7 +38,7 @@ trait Customers
* @throws \RetailCrm\Exception\CurlException
* @throws \RetailCrm\Exception\InvalidJsonException
*
* @return ApiResponse
* @return \RetailCrm\Response\ApiResponse
*/
public function customersList(array $filter = [], $page = null, $limit = null)
{
@ -71,7 +71,7 @@ trait Customers
* @throws \RetailCrm\Exception\CurlException
* @throws \RetailCrm\Exception\InvalidJsonException
*
* @return ApiResponse
* @return \RetailCrm\Response\ApiResponse
*/
public function customersCreate(array $customer, $site = null)
{
@ -97,7 +97,7 @@ trait Customers
* @throws \RetailCrm\Exception\CurlException
* @throws \RetailCrm\Exception\InvalidJsonException
*
* @return ApiResponse
* @return \RetailCrm\Response\ApiResponse
*/
public function customersFixExternalIds(array $ids)
{
@ -124,7 +124,7 @@ trait Customers
* @throws \RetailCrm\Exception\CurlException
* @throws \RetailCrm\Exception\InvalidJsonException
*
* @return ApiResponse
* @return \RetailCrm\Response\ApiResponse
*/
public function customersUpload(array $customers, $site = null)
{
@ -152,7 +152,7 @@ trait Customers
* @throws \RetailCrm\Exception\CurlException
* @throws \RetailCrm\Exception\InvalidJsonException
*
* @return ApiResponse
* @return \RetailCrm\Response\ApiResponse
*/
public function customersGet($id, $by = 'externalId', $site = null)
{
@ -176,7 +176,7 @@ trait Customers
* @throws \RetailCrm\Exception\CurlException
* @throws \RetailCrm\Exception\InvalidJsonException
*
* @return ApiResponse
* @return \RetailCrm\Response\ApiResponse
*/
public function customersEdit(array $customer, $by = 'externalId', $site = null)
{

View file

@ -39,7 +39,7 @@ trait Orders
* @throws \RetailCrm\Exception\CurlException
* @throws \RetailCrm\Exception\InvalidJsonException
*
* @return ApiResponse
* @return \RetailCrm\Response\ApiResponse
*/
public function ordersList(array $filter = [], $page = null, $limit = null)
{
@ -72,7 +72,7 @@ trait Orders
* @throws \RetailCrm\Exception\CurlException
* @throws \RetailCrm\Exception\InvalidJsonException
*
* @return ApiResponse
* @return \RetailCrm\Response\ApiResponse
*/
public function ordersCreate(array $order, $site = null)
{
@ -98,7 +98,7 @@ trait Orders
* @throws \RetailCrm\Exception\CurlException
* @throws \RetailCrm\Exception\InvalidJsonException
*
* @return ApiResponse
* @return \RetailCrm\Response\ApiResponse
*/
public function ordersFixExternalIds(array $ids)
{
@ -126,7 +126,7 @@ trait Orders
* @throws \RetailCrm\Exception\CurlException
* @throws \RetailCrm\Exception\InvalidJsonException
*
* @return ApiResponse
* @return \RetailCrm\Response\ApiResponse
*/
public function ordersStatuses(array $ids = [], array $externalIds = [])
{
@ -156,7 +156,7 @@ trait Orders
* @throws \RetailCrm\Exception\CurlException
* @throws \RetailCrm\Exception\InvalidJsonException
*
* @return ApiResponse
* @return \RetailCrm\Response\ApiResponse
*/
public function ordersUpload(array $orders, $site = null)
{
@ -184,7 +184,7 @@ trait Orders
* @throws \RetailCrm\Exception\CurlException
* @throws \RetailCrm\Exception\InvalidJsonException
*
* @return ApiResponse
* @return \RetailCrm\Response\ApiResponse
*/
public function ordersGet($id, $by = 'externalId', $site = null)
{
@ -208,7 +208,7 @@ trait Orders
* @throws \RetailCrm\Exception\CurlException
* @throws \RetailCrm\Exception\InvalidJsonException
*
* @return ApiResponse
* @return \RetailCrm\Response\ApiResponse
*/
public function ordersEdit(array $order, $by = 'externalId', $site = null)
{
@ -242,7 +242,7 @@ trait Orders
* @param null $page
* @param null $limit
*
* @return ApiResponse
* @return \RetailCrm\Response\ApiResponse
*/
public function ordersHistory(array $filter = [], $page = null, $limit = null)
{

View file

@ -38,7 +38,7 @@ trait Packs
* @throws \RetailCrm\Exception\CurlException
* @throws \RetailCrm\Exception\InvalidJsonException
*
* @return ApiResponse
* @return \RetailCrm\Response\ApiResponse
*/
public function ordersPacksList(array $filter = [], $page = null, $limit = null)
{
@ -71,7 +71,7 @@ trait Packs
* @throws \RetailCrm\Exception\CurlException
* @throws \RetailCrm\Exception\InvalidJsonException
*
* @return ApiResponse
* @return \RetailCrm\Response\ApiResponse
*/
public function ordersPacksCreate(array $pack, $site = null)
{
@ -99,7 +99,7 @@ trait Packs
* @throws \RetailCrm\Exception\CurlException
* @throws \RetailCrm\Exception\InvalidJsonException
*
* @return ApiResponse
* @return \RetailCrm\Response\ApiResponse
*/
public function ordersPacksHistory(array $filter = [], $page = null, $limit = null)
{
@ -131,7 +131,7 @@ trait Packs
* @throws \RetailCrm\Exception\CurlException
* @throws \RetailCrm\Exception\InvalidJsonException
*
* @return ApiResponse
* @return \RetailCrm\Response\ApiResponse
*/
public function ordersPacksGet($id)
{
@ -154,7 +154,7 @@ trait Packs
* @throws \RetailCrm\Exception\CurlException
* @throws \RetailCrm\Exception\InvalidJsonException
*
* @return ApiResponse
* @return \RetailCrm\Response\ApiResponse
*/
public function ordersPacksDelete($id)
{
@ -178,7 +178,7 @@ trait Packs
* @throws \RetailCrm\Exception\CurlException
* @throws \RetailCrm\Exception\InvalidJsonException
*
* @return ApiResponse
* @return \RetailCrm\Response\ApiResponse
*/
public function ordersPacksEdit(array $pack, $site = null)
{

View file

@ -34,7 +34,7 @@ trait References
* @throws \RetailCrm\Exception\CurlException
* @throws \RetailCrm\Exception\InvalidJsonException
*
* @return ApiResponse
* @return \RetailCrm\Response\ApiResponse
*/
public function countriesList()
{
@ -51,7 +51,7 @@ trait References
* @throws \RetailCrm\Exception\CurlException
* @throws \RetailCrm\Exception\InvalidJsonException
*
* @return ApiResponse
* @return \RetailCrm\Response\ApiResponse
*/
public function deliveryServicesList()
{
@ -70,7 +70,7 @@ trait References
* @throws \RetailCrm\Exception\CurlException
* @throws \RetailCrm\Exception\InvalidJsonException
*
* @return ApiResponse
* @return \RetailCrm\Response\ApiResponse
*/
public function deliveryServicesEdit(array $data)
{
@ -94,7 +94,7 @@ trait References
* @throws \RetailCrm\Exception\CurlException
* @throws \RetailCrm\Exception\InvalidJsonException
*
* @return ApiResponse
* @return \RetailCrm\Response\ApiResponse
*/
public function deliveryTypesList()
{
@ -113,7 +113,7 @@ trait References
* @throws \RetailCrm\Exception\CurlException
* @throws \RetailCrm\Exception\InvalidJsonException
*
* @return ApiResponse
* @return \RetailCrm\Response\ApiResponse
*/
public function deliveryTypesEdit(array $data)
{
@ -137,7 +137,7 @@ trait References
* @throws \RetailCrm\Exception\CurlException
* @throws \RetailCrm\Exception\InvalidJsonException
*
* @return ApiResponse
* @return \RetailCrm\Response\ApiResponse
*/
public function orderMethodsList()
{
@ -156,7 +156,7 @@ trait References
* @throws \RetailCrm\Exception\CurlException
* @throws \RetailCrm\Exception\InvalidJsonException
*
* @return ApiResponse
* @return \RetailCrm\Response\ApiResponse
*/
public function orderMethodsEdit(array $data)
{
@ -180,7 +180,7 @@ trait References
* @throws \RetailCrm\Exception\CurlException
* @throws \RetailCrm\Exception\InvalidJsonException
*
* @return ApiResponse
* @return \RetailCrm\Response\ApiResponse
*/
public function orderTypesList()
{
@ -199,7 +199,7 @@ trait References
* @throws \RetailCrm\Exception\CurlException
* @throws \RetailCrm\Exception\InvalidJsonException
*
* @return ApiResponse
* @return \RetailCrm\Response\ApiResponse
*/
public function orderTypesEdit(array $data)
{
@ -223,7 +223,7 @@ trait References
* @throws \RetailCrm\Exception\CurlException
* @throws \RetailCrm\Exception\InvalidJsonException
*
* @return ApiResponse
* @return \RetailCrm\Response\ApiResponse
*/
public function paymentStatusesList()
{
@ -242,7 +242,7 @@ trait References
* @throws \RetailCrm\Exception\CurlException
* @throws \RetailCrm\Exception\InvalidJsonException
*
* @return ApiResponse
* @return \RetailCrm\Response\ApiResponse
*/
public function paymentStatusesEdit(array $data)
{
@ -266,7 +266,7 @@ trait References
* @throws \RetailCrm\Exception\CurlException
* @throws \RetailCrm\Exception\InvalidJsonException
*
* @return ApiResponse
* @return \RetailCrm\Response\ApiResponse
*/
public function paymentTypesList()
{
@ -285,7 +285,7 @@ trait References
* @throws \RetailCrm\Exception\CurlException
* @throws \RetailCrm\Exception\InvalidJsonException
*
* @return ApiResponse
* @return \RetailCrm\Response\ApiResponse
*/
public function paymentTypesEdit(array $data)
{
@ -309,7 +309,7 @@ trait References
* @throws \RetailCrm\Exception\CurlException
* @throws \RetailCrm\Exception\InvalidJsonException
*
* @return ApiResponse
* @return \RetailCrm\Response\ApiResponse
*/
public function productStatusesList()
{
@ -328,7 +328,7 @@ trait References
* @throws \RetailCrm\Exception\CurlException
* @throws \RetailCrm\Exception\InvalidJsonException
*
* @return ApiResponse
* @return \RetailCrm\Response\ApiResponse
*/
public function productStatusesEdit(array $data)
{
@ -352,7 +352,7 @@ trait References
* @throws \RetailCrm\Exception\CurlException
* @throws \RetailCrm\Exception\InvalidJsonException
*
* @return ApiResponse
* @return \RetailCrm\Response\ApiResponse
*/
public function sitesList()
{
@ -371,7 +371,7 @@ trait References
* @throws \RetailCrm\Exception\CurlException
* @throws \RetailCrm\Exception\InvalidJsonException
*
* @return ApiResponse
* @return \RetailCrm\Response\ApiResponse
*/
public function sitesEdit(array $data)
{
@ -395,7 +395,7 @@ trait References
* @throws \RetailCrm\Exception\CurlException
* @throws \RetailCrm\Exception\InvalidJsonException
*
* @return ApiResponse
* @return \RetailCrm\Response\ApiResponse
*/
public function statusGroupsList()
{
@ -412,7 +412,7 @@ trait References
* @throws \RetailCrm\Exception\CurlException
* @throws \RetailCrm\Exception\InvalidJsonException
*
* @return ApiResponse
* @return \RetailCrm\Response\ApiResponse
*/
public function statusesList()
{
@ -431,7 +431,7 @@ trait References
* @throws \RetailCrm\Exception\CurlException
* @throws \RetailCrm\Exception\InvalidJsonException
*
* @return ApiResponse
* @return \RetailCrm\Response\ApiResponse
*/
public function statusesEdit(array $data)
{
@ -455,7 +455,7 @@ trait References
* @throws \RetailCrm\Exception\CurlException
* @throws \RetailCrm\Exception\InvalidJsonException
*
* @return ApiResponse
* @return \RetailCrm\Response\ApiResponse
*/
public function storesList()
{
@ -474,7 +474,7 @@ trait References
* @throws \RetailCrm\Exception\CurlException
* @throws \RetailCrm\Exception\InvalidJsonException
*
* @return ApiResponse
* @return \RetailCrm\Response\ApiResponse
*/
public function storesEdit(array $data)
{

View file

@ -12,9 +12,7 @@
* @link http://www.retailcrm.ru/docs/Developers/ApiVersion5
*/
namespace RetailCrm\Methods;
use RetailCrm\Response\ApiResponse;
namespace RetailCrm\Methods\V3;
/**
* PHP version 5.4
@ -36,7 +34,7 @@ trait Statistic
* @throws \RetailCrm\Exception\CurlException
* @throws \RetailCrm\Exception\InvalidJsonException
*
* @return ApiResponse
* @return \RetailCrm\Response\ApiResponse
*/
public function statisticUpdate()
{

View file

@ -38,7 +38,7 @@ trait Stores
* @throws \RetailCrm\Exception\CurlException
* @throws \RetailCrm\Exception\InvalidJsonException
*
* @return ApiResponse
* @return \RetailCrm\Response\ApiResponse
*/
public function storeInventories(array $filter = [], $page = null, $limit = null)
{
@ -71,7 +71,7 @@ trait Stores
* @throws \RetailCrm\Exception\CurlException
* @throws \RetailCrm\Exception\InvalidJsonException
*
* @return ApiResponse
* @return \RetailCrm\Response\ApiResponse
*/
public function storeInventoriesUpload(array $offers, $site = null)
{

View file

@ -36,7 +36,7 @@ trait Telephony
* @throws \RetailCrm\Exception\CurlException
* @throws \InvalidArgumentException
*
* @return ApiResponse
* @return \RetailCrm\Response\ApiResponse
*/
public function telephonySettingsGet($code)
{
@ -60,7 +60,7 @@ trait Telephony
* @param string $externalPhone
* @param array $webAnalyticsData
*
* @return ApiResponse
* @return \RetailCrm\Response\ApiResponse
* @internal param string $code additional phone code
* @internal param string $status call status
*
@ -109,7 +109,7 @@ trait Telephony
* @throws \RetailCrm\Exception\CurlException
* @throws \RetailCrm\Exception\InvalidJsonException
*
* @return ApiResponse
* @return \RetailCrm\Response\ApiResponse
*/
public function telephonyCallsUpload(array $calls)
{
@ -136,7 +136,7 @@ trait Telephony
* @throws \RetailCrm\Exception\CurlException
* @throws \RetailCrm\Exception\InvalidJsonException
*
* @return ApiResponse
* @return \RetailCrm\Response\ApiResponse
*/
public function telephonyCallManager($phone, $details)
{

View file

@ -37,7 +37,7 @@ trait Customers
* @param null $page
* @param null $limit
*
* @return ApiResponse
* @return \RetailCrm\Response\ApiResponse
*/
public function customersHistory(array $filter = [], $page = null, $limit = null)
{

View file

@ -36,7 +36,7 @@ trait Delivery
* @throws \RetailCrm\Exception\CurlException
* @throws \RetailCrm\Exception\InvalidJsonException
*
* @return ApiResponse
* @return \RetailCrm\Response\ApiResponse
*/
public function deliverySettingsGet($code)
{
@ -59,7 +59,7 @@ trait Delivery
* @throws \RetailCrm\Exception\CurlException
* @throws \InvalidArgumentException
*
* @return ApiResponse
* @return \RetailCrm\Response\ApiResponse
*/
public function deliverySettingsEdit(array $configuration)
{
@ -86,7 +86,7 @@ trait Delivery
* @throws \RetailCrm\Exception\CurlException
* @throws \InvalidArgumentException
*
* @return ApiResponse
* @return \RetailCrm\Response\ApiResponse
*/
public function deliveryTracking($code, array $statusUpdate)
{

View file

@ -37,7 +37,7 @@ trait Marketplace
* @throws \RetailCrm\Exception\CurlException
* @throws \InvalidArgumentException
*
* @return ApiResponse
* @return \RetailCrm\Response\ApiResponse
*/
public function marketplaceSettingsEdit(array $configuration)
{

View file

@ -43,7 +43,7 @@ trait Orders
* @throws \RetailCrm\Exception\CurlException
* @throws \RetailCrm\Exception\InvalidJsonException
*
* @return ApiResponse
* @return \RetailCrm\Response\ApiResponse
*/
public function ordersList(array $filter = [], $page = null, $limit = null)
{
@ -76,7 +76,7 @@ trait Orders
* @throws \RetailCrm\Exception\CurlException
* @throws \RetailCrm\Exception\InvalidJsonException
*
* @return ApiResponse
* @return \RetailCrm\Response\ApiResponse
*/
public function ordersCreate(array $order, $site = null)
{
@ -102,7 +102,7 @@ trait Orders
* @throws \RetailCrm\Exception\CurlException
* @throws \RetailCrm\Exception\InvalidJsonException
*
* @return ApiResponse
* @return \RetailCrm\Response\ApiResponse
*/
public function ordersFixExternalIds(array $ids)
{
@ -130,7 +130,7 @@ trait Orders
* @throws \RetailCrm\Exception\CurlException
* @throws \RetailCrm\Exception\InvalidJsonException
*
* @return ApiResponse
* @return \RetailCrm\Response\ApiResponse
*/
public function ordersStatuses(array $ids = [], array $externalIds = [])
{
@ -160,7 +160,7 @@ trait Orders
* @throws \RetailCrm\Exception\CurlException
* @throws \RetailCrm\Exception\InvalidJsonException
*
* @return ApiResponse
* @return \RetailCrm\Response\ApiResponse
*/
public function ordersUpload(array $orders, $site = null)
{
@ -188,7 +188,7 @@ trait Orders
* @throws \RetailCrm\Exception\CurlException
* @throws \RetailCrm\Exception\InvalidJsonException
*
* @return ApiResponse
* @return \RetailCrm\Response\ApiResponse
*/
public function ordersGet($id, $by = 'externalId', $site = null)
{
@ -212,7 +212,7 @@ trait Orders
* @throws \RetailCrm\Exception\CurlException
* @throws \RetailCrm\Exception\InvalidJsonException
*
* @return ApiResponse
* @return \RetailCrm\Response\ApiResponse
*/
public function ordersEdit(array $order, $by = 'externalId', $site = null)
{
@ -246,7 +246,7 @@ trait Orders
* @param null $page
* @param null $limit
*
* @return ApiResponse
* @return \RetailCrm\Response\ApiResponse
*/
public function ordersHistory(array $filter = [], $page = null, $limit = null)
{

View file

@ -37,7 +37,7 @@ trait References
* @throws \RetailCrm\Exception\CurlException
* @throws \RetailCrm\Exception\InvalidJsonException
*
* @return ApiResponse
* @return \RetailCrm\Response\ApiResponse
*/
public function pricesTypes()
{
@ -56,7 +56,7 @@ trait References
* @throws \RetailCrm\Exception\CurlException
* @throws \RetailCrm\Exception\InvalidJsonException
*
* @return ApiResponse
* @return \RetailCrm\Response\ApiResponse
*/
public function pricesTypesEdit(array $data)
{

View file

@ -0,0 +1,33 @@
<?php
/**
* PHP version 5.4
*
* TaskTrait
*
* @category RetailCrm
* @package RetailCrm
* @author RetailCrm <integration@retailcrm.ru>
* @license https://opensource.org/licenses/MIT MIT License
* @link http://www.retailcrm.ru/docs/Developers/ApiVersion5
*/
namespace RetailCrm\Methods\V4;
use RetailCrm\Methods\V3\Statistic as Previous;
/**
* PHP version 5.4
*
* TaskTrait class
*
* @category RetailCrm
* @package RetailCrm
* @author RetailCrm <integration@retailcrm.ru>
* @license https://opensource.org/licenses/MIT MIT License
* @link http://www.retailcrm.ru/docs/Developers/ApiVersion5
*/
trait Statistic
{
use Previous;
}

View file

@ -36,12 +36,12 @@ trait Stores
*
* @param string $code get settings code
*
* @return ApiResponse
* @return \RetailCrm\Response\ApiResponse
* @throws \RetailCrm\Exception\InvalidJsonException
* @throws \RetailCrm\Exception\CurlException
* @throws \InvalidArgumentException
*
* @return ApiResponse
* @return \RetailCrm\Response\ApiResponse
*/
public function storeSettingsGet($code)
{
@ -64,7 +64,7 @@ trait Stores
* @throws \RetailCrm\Exception\CurlException
* @throws \InvalidArgumentException
*
* @return ApiResponse
* @return \RetailCrm\Response\ApiResponse
*/
public function storeSettingsEdit(array $configuration)
{
@ -91,7 +91,7 @@ trait Stores
* @throws \RetailCrm\Exception\CurlException
* @throws \RetailCrm\Exception\InvalidJsonException
*
* @return ApiResponse
* @return \RetailCrm\Response\ApiResponse
*/
public function storePricesUpload(array $prices, $site = null)
{
@ -119,7 +119,7 @@ trait Stores
* @throws \RetailCrm\Exception\CurlException
* @throws \RetailCrm\Exception\InvalidJsonException
*
* @return ApiResponse
* @return \RetailCrm\Response\ApiResponse
*/
public function storeProducts(array $filter = [], $page = null, $limit = null)
{

View file

@ -49,7 +49,7 @@ trait Telephony
* @param bool $hangupEventSupported
* @param bool $changeUserStatusUrl
*
* @return ApiResponse
* @return \RetailCrm\Response\ApiResponse
*/
public function telephonySettingsEdit(
$code,

View file

@ -38,7 +38,7 @@ trait Users
* @throws \RetailCrm\Exception\CurlException
* @throws \InvalidArgumentException
*
* @return ApiResponse
* @return \RetailCrm\Response\ApiResponse
*/
public function usersList(array $filter = [], $page = null, $limit = null)
{
@ -54,6 +54,7 @@ trait Users
$parameters['limit'] = (int)$limit;
}
/** @noinspection PhpUndefinedMethodInspection */
return $this->client->makeRequest(
'/users',
$this->client::METHOD_GET,
@ -70,7 +71,7 @@ trait Users
* @throws \RetailCrm\Exception\InvalidJsonException
* @throws \RetailCrm\Exception\CurlException
*
* @return ApiResponse
* @return \RetailCrm\Response\ApiResponse
*/
public function usersGroups($page = null, $limit = null)
{
@ -83,6 +84,7 @@ trait Users
$parameters['limit'] = (int)$limit;
}
/** @noinspection PhpUndefinedMethodInspection */
return $this->client->makeRequest(
'/user-groups',
$this->client::METHOD_GET,
@ -99,10 +101,11 @@ trait Users
* @throws \RetailCrm\Exception\CurlException
* @throws \InvalidArgumentException
*
* @return ApiResponse
* @return \RetailCrm\Response\ApiResponse
*/
public function usersGet($id)
{
/** @noinspection PhpUndefinedMethodInspection */
return $this->client->makeRequest("/users/$id", $this->client::METHOD_GET);
}
}

View file

@ -34,7 +34,7 @@ trait CustomFields
* @param null $limit
* @param null $page
*
* @return ApiResponse
* @return \RetailCrm\Response\ApiResponse
*/
public function customFieldsList(array $filter = [], $limit = null, $page = null)
{
@ -63,7 +63,7 @@ trait CustomFields
* @param $entity
* @param $customField
*
* @return ApiResponse
* @return \RetailCrm\Response\ApiResponse
*/
public function customFieldsCreate($entity, $customField)
{
@ -96,7 +96,7 @@ trait CustomFields
* @param $entity
* @param $customField
*
* @return ApiResponse
* @return \RetailCrm\Response\ApiResponse
*/
public function customFieldsEdit($entity, $customField)
{
@ -125,7 +125,7 @@ trait CustomFields
* @param $entity
* @param $code
*
* @return ApiResponse
* @return \RetailCrm\Response\ApiResponse
*/
public function customFieldsGet($entity, $code)
{
@ -154,7 +154,7 @@ trait CustomFields
* @param null $limit
* @param null $page
*
* @return ApiResponse
* @return \RetailCrm\Response\ApiResponse
*/
public function customDictionariesList(array $filter = [], $limit = null, $page = null)
{
@ -182,7 +182,7 @@ trait CustomFields
*
* @param $customDictionary
*
* @return ApiResponse
* @return \RetailCrm\Response\ApiResponse
*/
public function customDictionariesCreate($customDictionary)
{
@ -207,7 +207,7 @@ trait CustomFields
*
* @param $customDictionary
*
* @return ApiResponse
* @return \RetailCrm\Response\ApiResponse
*/
public function customDictionariesEdit($customDictionary)
{
@ -232,7 +232,7 @@ trait CustomFields
*
* @param $code
*
* @return ApiResponse
* @return \RetailCrm\Response\ApiResponse
*/
public function customDictionariesGet($code)
{

View file

@ -37,7 +37,7 @@ trait Customers
* @param array $customers
* @param array $resultCustomer
*
* @return ApiResponse
* @return \RetailCrm\Response\ApiResponse
*/
public function customersCombine(array $customers, $resultCustomer)
{

View file

@ -39,7 +39,7 @@ trait Orders
* @param array $order
* @param array $resultOrder
*
* @return ApiResponse
* @return \RetailCrm\Response\ApiResponse
*/
public function ordersCombine($order, $resultOrder, $technique = 'ours')
{
@ -77,7 +77,7 @@ trait Orders
* @throws \RetailCrm\Exception\CurlException
* @throws \RetailCrm\Exception\InvalidJsonException
*
* @return ApiResponse
* @return \RetailCrm\Response\ApiResponse
*/
public function ordersPaymentCreate(array $payment)
{
@ -101,7 +101,7 @@ trait Orders
* @param string $by by key
* @param null $site site code
*
* @return ApiResponse
* @return \RetailCrm\Response\ApiResponse
*/
public function ordersPaymentEdit(array $payment, $by = 'id', $site = null)
{

View file

@ -34,7 +34,7 @@ trait Segments
* @param null $limit
* @param null $page
*
* @return ApiResponse
* @return \RetailCrm\Response\ApiResponse
*/
public function segmentsList(array $filter = [], $limit = null, $page = null)
{

View file

@ -0,0 +1,33 @@
<?php
/**
* PHP version 5.4
*
* TaskTrait
*
* @category RetailCrm
* @package RetailCrm
* @author RetailCrm <integration@retailcrm.ru>
* @license https://opensource.org/licenses/MIT MIT License
* @link http://www.retailcrm.ru/docs/Developers/ApiVersion5
*/
namespace RetailCrm\Methods\V5;
use RetailCrm\Methods\V3\Statistic as Previous;
/**
* PHP version 5.4
*
* TaskTrait class
*
* @category RetailCrm
* @package RetailCrm
* @author RetailCrm <integration@retailcrm.ru>
* @license https://opensource.org/licenses/MIT MIT License
* @link http://www.retailcrm.ru/docs/Developers/ApiVersion5
*/
trait Statistic
{
use Previous;
}

View file

@ -42,7 +42,7 @@ trait Stores
* @throws \RetailCrm\Exception\CurlException
* @throws \RetailCrm\Exception\InvalidJsonException
*
* @return ApiResponse
* @return \RetailCrm\Response\ApiResponse
*/
public function storeProductsGroups(array $filter = [], $page = null, $limit = null)
{

View file

@ -34,7 +34,7 @@ trait Tasks
* @param null $limit
* @param null $page
*
* @return ApiResponse
* @return \RetailCrm\Response\ApiResponse
*/
public function tasksList(array $filter = [], $limit = null, $page = null)
{
@ -63,7 +63,7 @@ trait Tasks
* @param array $task
* @param null $site
*
* @return ApiResponse
* @return \RetailCrm\Response\ApiResponse
*
*/
public function tasksCreate($task, $site = null)
@ -90,7 +90,7 @@ trait Tasks
* @param array $task
* @param null $site
*
* @return ApiResponse
* @return \RetailCrm\Response\ApiResponse
*
*/
public function tasksEdit($task, $site = null)
@ -116,7 +116,7 @@ trait Tasks
*
* @param $id
*
* @return ApiResponse
* @return \RetailCrm\Response\ApiResponse
*/
public function tasksGet($id)
{

View file

@ -38,7 +38,7 @@ trait Users
* @param integer $id user ID
* @param string $status user status
*
* @return ApiResponse
* @return \RetailCrm\Response\ApiResponse
*/
public function usersStatus($id, $status)
{
@ -50,6 +50,7 @@ trait Users
);
}
/** @noinspection PhpUndefinedMethodInspection */
return $this->client->makeRequest(
"/users/$id/status",
$this->client::METHOD_POST,

View file

@ -21,6 +21,7 @@ use RetailCrm\Exception\InvalidJsonException;
*
* Response from retailCRM API
*
* @property mixed success
* @category RetailCrm
* @package RetailCrm
* @author RetailCrm <integration@retailcrm.ru>

View file

@ -39,13 +39,12 @@ class TestCase extends \PHPUnit_Framework_TestCase
$configUrl = getenv('CRM_API_URL') ?: $_SERVER['CRM_API_URL'];
$configKey = getenv('CRM_API_KEY') ?: $_SERVER['CRM_API_KEY'];
$configVersion = getenv('CRM_API_VERSION') ?: $_SERVER['CRM_API_VERSION'];
$configSite = getenv('CRM_API_SITE') ?: $_SERVER['CRM_API_SITE'];
return new ApiClient(
$url ?: $configUrl,
$apiKey ?: $configKey,
$version ?: $configVersion,
$site ?: (isset($configSite) ? $configSite: null)
$site ?: null
);
}
@ -59,8 +58,14 @@ class TestCase extends \PHPUnit_Framework_TestCase
*/
public static function getClient($url = null, $defaultParameters = [])
{
$version = getenv('CRM_API_VERSION');
if (false == $version) {
$version = $_SERVER['CRM_API_VERSION'];
}
return new Client(
$url ?: $_SERVER['CRM_URL'] . '/api/' . getenv('CRM_API_VERSION') ?: $_SERVER['CRM_API_VERSION'],
$url ?: $_SERVER['CRM_API_URL'] . '/api/' . $version,
[
'apiKey' => array_key_exists('apiKey', $defaultParameters)
? $defaultParameters['apiKey']

View file

@ -28,7 +28,7 @@ use RetailCrm\Test\TestCase;
class ApiClientTest extends TestCase
{
/**
* @group unit
* @group client
*/
public function testConstruct()
{

View file

@ -30,7 +30,7 @@ use RetailCrm\Http\Client;
class ClientTest extends TestCase
{
/**
* @group unit
* @group client
*/
public function testConstruct()
{
@ -40,17 +40,17 @@ class ClientTest extends TestCase
}
/**
* @group unit
* @group client
* @expectedException \InvalidArgumentException
*/
public function testHttpRequiring()
{
$client = new Client('http://demo.retailcrm.ru/api/' . ApiClient::VERSION, ['apiKey' => '123']);
$client = new Client('http://demo.retailcrm.ru/api/' . $_SERVER['CRM_API_VERSION'], ['apiKey' => '123']);
return $client;
}
/**
* @group unit
* @group client
* @expectedException \InvalidArgumentException
*/
public function testRequestWrongMethod()
@ -60,7 +60,7 @@ class ClientTest extends TestCase
}
/**
* @group integration
* @group client
* @expectedException \RetailCrm\Exception\CurlException
*/
public function testRequestWrongUrl()
@ -70,7 +70,7 @@ class ClientTest extends TestCase
}
/**
* @group integration
* @group client
*/
public function testRequestSuccess()
{

View file

@ -0,0 +1,286 @@
<?php
/**
* PHP version 5.4
*
* API client customers test class
*
* @category RetailCrm
* @package RetailCrm
* @author RetailCrm <integration@retailcrm.ru>
* @license https://opensource.org/licenses/MIT MIT License
* @link http://www.retailcrm.ru/docs/Developers/ApiVersion5
*/
namespace RetailCrm\Tests\Methods\Version4;
use RetailCrm\Test\TestCase;
/**
* Class ApiClientCustomersTest
*
* @category RetailCrm
* @package RetailCrm
* @author RetailCrm <integration@retailcrm.ru>
* @license https://opensource.org/licenses/MIT MIT License
* @link http://www.retailcrm.ru/docs/Developers/ApiVersion5
*/
class ApiClientCustomersTest extends TestCase
{
const FIRST_NAME = 'Иннокентий';
/**
* @group customers_v4
*/
public function testCustomersCreate()
{
$client = static::getApiClient(null, null, 'v4');
$externalId = 'c-create-' . time();
$response = $client->request->customersCreate([
'firstName' => self::FIRST_NAME,
'externalId' => $externalId,
]);
static::assertInstanceOf('RetailCrm\Response\ApiResponse', $response);
static::assertEquals(201, $response->getStatusCode());
static::assertTrue(is_int($response['id']));
return [
'id' => $response['id'],
'externalId' => $externalId,
];
}
/**
* @group customers_v4
* @expectedException \InvalidArgumentException
*/
public function testCreateExceptionEmpty()
{
$client = static::getApiClient(null, null, 'v4');
$client->request->customersCreate([]);
}
/**
* @group customers
* @depends testCustomersCreate
*
* @param array $ids
*
* @return array
*/
public function testCustomersGet(array $ids)
{
$client = static::getApiClient(null, null, 'v4');
$response = $client->request->customersGet(678678678);
static::assertInstanceOf('RetailCrm\Response\ApiResponse', $response);
static::assertEquals(404, $response->getStatusCode());
static::assertFalse($response->isSuccessful());
$response = $client->request->customersGet($ids['id'], 'id');
$customerById = $response['customer'];
static::assertInstanceOf('RetailCrm\Response\ApiResponse', $response);
static::assertEquals(200, $response->getStatusCode());
static::assertTrue($response->isSuccessful());
static::assertEquals(self::FIRST_NAME, $response['customer']['firstName']);
$response = $client->request->customersGet($ids['externalId'], 'externalId');
static::assertEquals($customerById['id'], $response['customer']['id']);
return $ids;
}
/**
* @group customers_v4
* @expectedException \InvalidArgumentException
*/
public function testCustomersGetException()
{
$client = static::getApiClient(null, null, 'v4');
$client->request->customersGet(678678678, 'asdf');
}
/**
* @group customers
* @depends testCustomersGet
*
* @param array $ids
*/
public function testCustomersEdit(array $ids)
{
$client = static::getApiClient(null, null, 'v4');
$response = $client->request->customersEdit(
[
'id' => 22342134,
'lastName' => '12345',
],
'id'
);
static::assertInstanceOf('RetailCrm\Response\ApiResponse', $response);
static::assertEquals(404, $response->getStatusCode());
$response = $client->request->customersEdit([
'externalId' => $ids['externalId'],
'lastName' => '12345',
]);
static::assertInstanceOf('RetailCrm\Response\ApiResponse', $response);
static::assertEquals(200, $response->getStatusCode());
static::assertTrue($response->isSuccessful());
}
/**
* @group customers_v4
* @expectedException \InvalidArgumentException
*/
public function testCustomersEditExceptionEmpty()
{
$client = static::getApiClient(null, null, 'v4');
$client->request->customersEdit([], 'asdf');
}
/**
* @group customers_v4
* @expectedException \InvalidArgumentException
*/
public function testCustomersEditException()
{
$client = static::getApiClient(null, null, 'v4');
$client->request->customersEdit(['id' => 678678678], 'asdf');
}
/**
* @group customers_v4
*/
public function testCustomersList()
{
$client = static::getApiClient(null, null, 'v4');
$response = $client->request->customersList();
static::assertInstanceOf('RetailCrm\Response\ApiResponse', $response);
static::assertTrue($response->isSuccessful());
static::assertTrue(isset($response['customers']));
$response = $client->request->customersList([], 1, 300);
static::assertInstanceOf('RetailCrm\Response\ApiResponse', $response);
static::assertFalse(
$response->isSuccessful(),
'Pagination error'
);
$response = $client->request->customersList(['maxOrdersCount' => 10], 1);
static::assertInstanceOf('RetailCrm\Response\ApiResponse', $response);
static::assertTrue(
$response->isSuccessful(),
'API returns customers list'
);
}
/**
* @group customers_v4
* @expectedException \InvalidArgumentException
*/
public function testCustomersFixExternalIdsException()
{
$client = static::getApiClient(null, null, 'v4');
$client->request->customersFixExternalIds([]);
}
/**
* @group customers_v4
*/
public function testCustomersFixExternalIds()
{
$client = static::getApiClient(null, null, 'v4');
$response = $client->request->ordersCreate([
'firstName' => 'Aaa111',
]);
static::assertTrue(
$response->isSuccessful(),
'Order created'
);
$response = $client->request->ordersGet($response['id'], 'id');
static::assertTrue(
$response->isSuccessful(),
'Order fetched'
);
$id = $response['order']['customer']['id'];
$externalId = 'asdf' . time();
$response = $client->request->customersFixExternalIds([
['id' => $id, 'externalId' => $externalId]
]);
static::assertTrue(
$response->isSuccessful(),
'Fixed customer ids'
);
$response = $client->request->customersGet($externalId);
static::assertTrue(
$response->isSuccessful(),
'Got customer'
);
static::assertEquals(
$id,
$response['customer']['id'],
'Fixing of customer ids were right'
);
static::assertEquals(
$externalId,
$response['customer']['externalId'],
'Fixing of customer ids were right'
);
}
/**
* @group customers_v4
* @expectedException \InvalidArgumentException
*/
public function testCustomersUploadExceptionEmpty()
{
$client = static::getApiClient(null, null, 'v4');
$client->request->customersUpload([]);
}
/**
* @group customers_v4
*/
public function testCustomersUpload()
{
$client = static::getApiClient(null, null, 'v4');
$externalIdA = 'upload-a-' . time();
$externalIdB = 'upload-b-' . time();
$response = $client->request->customersUpload([
[
'externalId' => $externalIdA,
'firstName' => 'Aaa',
],
[
'externalId' => $externalIdB,
'lastName' => 'Bbb',
],
]);
static::assertTrue(
$response->isSuccessful(),
'Got customer'
);
static::assertEquals(
$externalIdA,
$response['uploadedCustomers'][0]['externalId']
);
static::assertEquals(
$externalIdB,
$response['uploadedCustomers'][1]['externalId']
);
}
}

View file

@ -12,7 +12,7 @@
* @link http://www.retailcrm.ru/docs/Developers/ApiVersion5
*/
namespace RetailCrm\Tests;
namespace RetailCrm\Tests\Methods\Version4;
use RetailCrm\Test\TestCase;
@ -23,17 +23,17 @@ use RetailCrm\Test\TestCase;
*/
class ApiClientMarketplaceTest extends TestCase
{
const SNAME = 'Marketplace integration';
const SCODE = 'integration';
const SNAME = 'Marketplace integration v4';
const SCODE = 'integration_v4';
/**
* @group marketplace
* @group marketplace_v4
*/
public function testConfigurationEdit()
{
$client = static::getApiClient();
$client = static::getApiClient(null, null, "v4");
$response = $client->marketplaceSettingsEdit(
$response = $client->request->marketplaceSettingsEdit(
[
'name' => self::SNAME,
'code' => self::SCODE,

View file

@ -0,0 +1,332 @@
<?php
/**
* PHP version 5.4
*
* API client orders test class
*
* @category RetailCrm
* @package RetailCrm
* @author RetailCrm <integration@retailcrm.ru>
* @license https://opensource.org/licenses/MIT MIT License
* @link http://www.retailcrm.ru/docs/Developers/ApiVersion5
*/
namespace RetailCrm\Tests\Methods\Version4;
use RetailCrm\Test\TestCase;
/**
* Class ApiClientOrdersTest
*
* @category RetailCrm
* @package RetailCrm
* @author RetailCrm <integration@retailcrm.ru>
* @license https://opensource.org/licenses/MIT MIT License
* @link http://www.retailcrm.ru/docs/Developers/ApiVersion5
*/
class ApiClientOrdersTest extends TestCase
{
const FIRST_NAME = 'Иннокентий';
/**
* @group orders_v4
*/
public function testOrdersCreate()
{
$client = static::getApiClient(null, null, 'v4');
$externalId = 'o-create-' . time();
$response = $client->request->ordersCreate([
'firstName' => self::FIRST_NAME,
'externalId' => $externalId,
]);
static::assertInstanceOf('RetailCrm\Response\ApiResponse', $response);
static::assertEquals(201, $response->getStatusCode());
static::assertTrue(is_int($response['id']));
return [
'id' => $response['id'],
'externalId' => $externalId,
];
}
/**
* @group orders_v4
* @expectedException \InvalidArgumentException
*/
public function testOrdersCreateExceptionEmpty()
{
$client = static::getApiClient(null, null, 'v4');
$client->request->ordersCreate([]);
}
/**
* @group orders
* @depends testOrdersCreate
*
* @param array $ids
*/
public function testOrdersStatuses(array $ids)
{
$client = static::getApiClient(null, null, 'v4');
$response = $client->request->ordersStatuses();
static::assertInstanceOf('RetailCrm\Response\ApiResponse', $response);
static::assertEquals(400, $response->getStatusCode());
static::assertFalse($response->isSuccessful());
$response = $client->request->ordersStatuses([], ['asdf']);
static::assertInstanceOf('RetailCrm\Response\ApiResponse', $response);
static::assertEquals(200, $response->getStatusCode());
static::assertTrue($response->isSuccessful());
$orders = $response['orders'];
static::assertEquals(0, sizeof($orders));
$response = $client->request->ordersStatuses([], [$ids['externalId']]);
static::assertInstanceOf('RetailCrm\Response\ApiResponse', $response);
static::assertEquals(200, $response->getStatusCode());
static::assertTrue($response->isSuccessful());
$orders = $response['orders'];
static::assertEquals(1, sizeof($orders));
static::assertEquals('new', $orders[0]['status']);
$response = $client->request->ordersStatuses([$ids['id']], [$ids['externalId']]);
static::assertInstanceOf('RetailCrm\Response\ApiResponse', $response);
static::assertEquals(200, $response->getStatusCode());
static::assertTrue($response->isSuccessful());
$orders = $response['orders'];
static::assertEquals(1, sizeof($orders));
$response = $client->request->ordersStatuses([$ids['id']]);
static::assertInstanceOf('RetailCrm\Response\ApiResponse', $response);
static::assertEquals(200, $response->getStatusCode());
static::assertTrue($response->isSuccessful());
$orders = $response['orders'];
static::assertEquals(1, sizeof($orders));
}
/**
* @group orders
* @depends testOrdersCreate
*
* @param array $ids
*
* @return array
*/
public function testOrdersGet(array $ids)
{
$client = static::getApiClient(null, null, 'v4');
$response = $client->request->ordersGet(678678678);
static::assertInstanceOf('RetailCrm\Response\ApiResponse', $response);
static::assertEquals(404, $response->getStatusCode());
static::assertFalse($response->isSuccessful());
$response = $client->request->ordersGet($ids['id'], 'id');
$orderById = $response['order'];
static::assertInstanceOf('RetailCrm\Response\ApiResponse', $response);
static::assertEquals(200, $response->getStatusCode());
static::assertTrue($response->isSuccessful());
static::assertEquals(self::FIRST_NAME, $response['order']['firstName']);
$response = $client->request->ordersGet($ids['externalId'], 'externalId');
static::assertEquals($orderById['id'], $response['order']['id']);
return $ids;
}
/**
* @group orders_v4
* @expectedException \InvalidArgumentException
*/
public function testOrdersGetException()
{
$client = static::getApiClient(null, null, 'v4');
$client->request->ordersGet(678678678, 'asdf');
}
/**
* @group orders
* @depends testOrdersGet
*
* @param array $ids
*/
public function testOrdersEdit(array $ids)
{
$client = static::getApiClient(null, null, 'v4');
$response = $client->request->ordersEdit(
[
'id' => 22342134,
'lastName' => '12345',
],
'id'
);
static::assertInstanceOf('RetailCrm\Response\ApiResponse', $response);
static::assertEquals(404, $response->getStatusCode());
$response = $client->request->ordersEdit([
'externalId' => $ids['externalId'],
'lastName' => '12345',
]);
static::assertInstanceOf('RetailCrm\Response\ApiResponse', $response);
static::assertEquals(200, $response->getStatusCode());
static::assertTrue($response->isSuccessful());
}
/**
* @group orders_v4
* @expectedException \InvalidArgumentException
*/
public function testOrdersEditExceptionEmpty()
{
$client = static::getApiClient(null, null, 'v4');
$client->request->ordersEdit([], 'asdf');
}
/**
* @group orders_v4
* @expectedException \InvalidArgumentException
*/
public function testOrdersEditException()
{
$client = static::getApiClient(null, null, 'v4');
$client->request->ordersEdit(['id' => 678678678], 'asdf');
}
/**
* @group orders_v4
*/
public function testOrdersHistory()
{
$client = static::getApiClient(null, null, 'v4');
$response = $client->request->ordersHistory();
static::assertInstanceOf('RetailCrm\Response\ApiResponse', $response);
static::assertEquals(200, $response->getStatusCode());
static::assertTrue($response->isSuccessful());
}
/**
* @group orders_v4
*/
public function testOrdersList()
{
$client = static::getApiClient(null, null, 'v4');
$response = $client->request->ordersList();
static::assertInstanceOf('RetailCrm\Response\ApiResponse', $response);
static::assertTrue($response->isSuccessful());
static::assertTrue(isset($response['orders']));
$response = $client->request->ordersList([], 1, 300);
static::assertInstanceOf('RetailCrm\Response\ApiResponse', $response);
static::assertFalse(
$response->isSuccessful(),
'Pagination error'
);
$response = $client->request->ordersList(['paymentStatus' => 'paid'], 1);
static::assertInstanceOf('RetailCrm\Response\ApiResponse', $response);
}
/**
* @group orders_v4
* @expectedException \InvalidArgumentException
*/
public function testOrdersFixExternalIdsException()
{
$client = static::getApiClient(null, null, 'v4');
$client->request->ordersFixExternalIds([]);
}
/**
* @group orders_v4
*/
public function testOrdersFixExternalIds()
{
$client = static::getApiClient(null, null, 'v4');
$response = $client->request->ordersCreate([
'firstName' => 'Aaa',
]);
static::assertTrue(
$response->isSuccessful(),
'Order created'
);
$id = $response['id'];
$externalId = 'asdf' . time();
$response = $client->request->ordersFixExternalIds([
['id' => $id, 'externalId' => $externalId]
]);
static::assertTrue(
$response->isSuccessful(),
'Fixed order ids'
);
$response = $client->request->ordersGet($externalId);
static::assertTrue(
$response->isSuccessful(),
'Got order'
);
static::assertEquals(
$id,
$response['order']['id'],
'Fixing of order ids were right'
);
static::assertEquals(
$externalId,
$response['order']['externalId'],
'Fixing of order ids were right'
);
}
/**
* @group orders_v4
* @expectedException \InvalidArgumentException
*/
public function testOrdersUploadExceptionEmpty()
{
$client = static::getApiClient(null, null, 'v4');
$client->request->ordersUpload([]);
}
/**
* @group orders_v4
*/
public function testOrdersUpload()
{
$client = static::getApiClient(null, null, 'v4');
$externalIdA = 'upload-a-' . time();
$externalIdB = 'upload-b-' . time();
$response = $client->request->ordersUpload([
[
'externalId' => $externalIdA,
'firstName' => 'Aaa',
],
[
'externalId' => $externalIdB,
'lastName' => 'Bbb',
],
]);
static::assertTrue(
$response->isSuccessful(),
'Got order'
);
static::assertEquals(
$externalIdA,
$response['uploadedOrders'][0]['externalId']
);
static::assertEquals(
$externalIdB,
$response['uploadedOrders'][1]['externalId']
);
}
}

View file

@ -12,7 +12,7 @@
* @link http://www.retailcrm.ru/docs/Developers/ApiVersion5
*/
namespace RetailCrm\Tests;
namespace RetailCrm\Tests\Methods\Version4;
use RetailCrm\Test\TestCase;
@ -28,16 +28,13 @@ use RetailCrm\Test\TestCase;
class ApiClientPacksTest extends TestCase
{
/**
* Test packs history
*
* @group packs
* @return void
* @group packs_v4
*/
public function testPacksHistory()
{
$client = static::getApiClient();
$client = static::getApiClient(null, null, "v4");
$response = $client->ordersPacksHistory();
$response = $client->request->ordersPacksHistory();
static::assertInstanceOf('RetailCrm\Response\ApiResponse', $response);
static::assertEquals(200, $response->getStatusCode());
static::assertTrue($response->success);
@ -52,21 +49,18 @@ class ApiClientPacksTest extends TestCase
}
/**
* Test packs failed create
*
* @group packs
* @return void
* @group packs_v4
*/
public function testPacksCreateFailed()
{
$client = static::getApiClient();
$client = static::getApiClient(null, null, "v4");
$pack = [
'itemId' => 12,
'store' => 'test',
'quantity' => 2
];
$response = $client->ordersPacksCreate($pack);
$response = $client->request->ordersPacksCreate($pack);
static::assertInstanceOf('RetailCrm\Response\ApiResponse', $response);
static::assertEquals(400, $response->getStatusCode());
static::assertFalse($response->success);

View file

@ -12,7 +12,7 @@
* @link http://www.retailcrm.ru/docs/Developers/ApiVersion5
*/
namespace RetailCrm\Tests;
namespace RetailCrm\Tests\Methods\Version4;
use RetailCrm\Test\TestCase;
@ -28,91 +28,71 @@ use RetailCrm\Test\TestCase;
class ApiClientPricesTest extends TestCase
{
protected $code;
/**
* ApiClientPricesTest constructor.
*/
public function __construct()
{
parent::__construct();
$this->code = 'price-code-a-' . time();
}
/**
* @group prices
*/
public function testUsersGroups()
{
$client = static::getApiClient();
$response = $client->usersGroups();
static::assertInstanceOf('RetailCrm\Response\ApiResponse', $response);
static::assertEquals(200, $response->getStatusCode());
static::assertTrue($response->isSuccessful());
}
/**
* @group prices
*/
public function testPricesGet()
{
$client = static::getApiClient();
$response = $client->pricesTypes();
static::assertInstanceOf('RetailCrm\Response\ApiResponse', $response);
static::assertEquals(200, $response->getStatusCode());
static::assertTrue($response->isSuccessful());
}
/**
* @group prices
* @group prices_v4
*/
public function testPricesEdit()
{
$client = static::getApiClient();
$client = static::getApiClient(null, null, "v4");
$response = $client->pricesEdit(
$response = $client->request->pricesTypesEdit(
[
'code' => $this->code,
'name' => $this->code,
'code' => 'sample_v4_price_code',
'name' => 'Sample v4 price type',
'ordering' => 500,
'active' => true
]
);
static::assertInstanceOf('RetailCrm\Response\ApiResponse', $response);
static::assertEquals(201, $response->getStatusCode());
static::assertTrue(in_array($response->getStatusCode(), [200, 201]));
static::assertTrue($response->isSuccessful());
}
/**
* @group prices
* @depends testPricesEdit
* @group prices_v4
*/
public function testPricesGet()
{
$client = static::getApiClient(null, null, "v4");
$response = $client->request->pricesTypes();
static::assertInstanceOf('RetailCrm\Response\ApiResponse', $response);
static::assertEquals(200, $response->getStatusCode());
static::assertTrue($response->isSuccessful());
}
/**
* @group prices_v4
* @expectedException \InvalidArgumentException
*/
public function testPricesUploadExceptionEmpty()
{
$client = static::getApiClient();
$client->storePricesUpload([]);
$client = static::getApiClient(null, null, "v4");
$client->request->storePricesUpload([]);
}
/**
* @group prices
* @depends testPricesEdit
* @group prices_v4
*/
public function testPricesUpload()
{
$client = static::getApiClient();
$client = static::getApiClient(null, null, "v4");
$xmlIdA = 'upload-a-' . time();
$xmlIdB = 'upload-b-' . time();
$response = $client->storePricesUpload([
$response = $client->request->storePricesUpload([
[
'xmlId' => $xmlIdA,
'prices' => [
[
'code' => $this->code,
'code' => 'sample_v4_price_code',
'price' => 1700
]
]
@ -121,7 +101,7 @@ class ApiClientPricesTest extends TestCase
'xmlId' => $xmlIdB,
'prices' => [
[
'code' => $this->code,
'code' => 'sample_v4_price_code',
'price' => 1500
]
]

View file

@ -12,7 +12,7 @@
* @link http://www.retailcrm.ru/docs/Developers/ApiVersion5
*/
namespace RetailCrm\Tests;
namespace RetailCrm\Tests\Methods\Version4;
use RetailCrm\Test\TestCase;
@ -28,16 +28,16 @@ use RetailCrm\Test\TestCase;
class ApiClientReferenceTest extends TestCase
{
/**
* @group reference
* @group reference_v4
* @dataProvider getListDictionaries
* @param $name
*/
public function testList($name)
{
$client = static::getApiClient();
$client = static::getApiClient(null, null, 'v4');
$method = $name . 'List';
$response = $client->$method();
$response = $client->request->$method();
/* @var \RetailCrm\Response\ApiResponse $response */
@ -48,7 +48,7 @@ class ApiClientReferenceTest extends TestCase
}
/**
* @group reference
* @group reference_v4
* @dataProvider getEditDictionaries
* @expectedException \InvalidArgumentException
*
@ -56,21 +56,21 @@ class ApiClientReferenceTest extends TestCase
*/
public function testEditingException($name)
{
$client = static::getApiClient();
$client = static::getApiClient(null, null, 'v4');
$method = $name . 'Edit';
$client->$method([]);
$client->request->$method([]);
}
/**
* @group reference
* @group reference_v4
* @dataProvider getEditDictionaries
*
* @param $name
*/
public function testEditing($name)
{
$client = static::getApiClient();
$client = static::getApiClient(null, null, 'v4');
$code = 'dict-' . strtolower($name) . '-' . time();
$method = $name . 'Edit';
@ -83,12 +83,12 @@ class ApiClientReferenceTest extends TestCase
$params['group'] = 'new';
}
$response = $client->$method($params);
$response = $client->request->$method($params);
/* @var \RetailCrm\Response\ApiResponse $response */
static::assertTrue(in_array($response->getStatusCode(), [200, 201]));
$response = $client->$method([
$response = $client->request->$method([
'code' => $code,
'name' => 'Bbb' . $code,
'active' => false
@ -98,13 +98,13 @@ class ApiClientReferenceTest extends TestCase
}
/**
* @group reference
* @group reference_v4
* @group site
*/
public function testSiteEditing()
{
$name = 'sites';
$client = static::getApiClient();
$client = static::getApiClient(null, null, 'v4');
$code = 'dict-' . strtolower($name) . '-' . time();
$method = $name . 'Edit';
@ -114,12 +114,12 @@ class ApiClientReferenceTest extends TestCase
'active' => false
];
$response = $client->$method($params);
$response = $client->request->$method($params);
/* @var \RetailCrm\Response\ApiResponse $response */
static::assertEquals(400, $response->getStatusCode());
if ($code == $client->getSite()) {
if ($code == $client->request->getSite()) {
$method = $name . 'Edit';
$params = [
'code' => $code,
@ -127,7 +127,7 @@ class ApiClientReferenceTest extends TestCase
'active' => false
];
$response = $client->$method($params);
$response = $client->request->$method($params);
static::assertEquals(200, $response->getStatusCode());
}
}
@ -148,6 +148,7 @@ class ApiClientReferenceTest extends TestCase
['statusGroups'],
['statuses'],
['sites'],
['stores'],
];
}

View file

@ -0,0 +1,146 @@
<?php
/**
* PHP version 5.4
*
* API client store test class
*
* @category RetailCrm
* @package RetailCrm
* @author RetailCrm <integration@retailcrm.ru>
* @license https://opensource.org/licenses/MIT MIT License
* @link http://www.retailcrm.ru/docs/Developers/ApiVersion5
*/
namespace RetailCrm\Tests\Methods\Version4;
use RetailCrm\Test\TestCase;
/**
* Class ApiClientStoreTest
*
* @category RetailCrm
* @package RetailCrm
* @author RetailCrm <integration@retailcrm.ru>
* @license https://opensource.org/licenses/MIT MIT License
* @link http://www.retailcrm.ru/docs/Developers/ApiVersion5
*/
class ApiClientStoreTest extends TestCase
{
const SNAME = 'Test Store V4';
const SCODE = 'test-store-v4';
/**
* @group store_v4
*/
public function testStoreCreate()
{
$client = static::getApiClient(null, null, 'v4');
$response = $client->request->storesEdit(['name' => self::SNAME, 'code' => self::SCODE]);
static::assertInstanceOf('RetailCrm\Response\ApiResponse', $response);
static::assertTrue(in_array($response->getStatusCode(), [200, 201]));
static::assertTrue($response->isSuccessful());
}
/**
* @group store_v4
*/
public function testStoreInventories()
{
$client = static::getApiClient(null, null, 'v4');
$response = $client->request->storeInventories();
static::assertInstanceOf('RetailCrm\Response\ApiResponse', $response);
static::assertEquals(200, $response->getStatusCode());
static::assertTrue($response->isSuccessful());
static::assertTrue(
isset($response['offers']),
'API returns orders assembly history'
);
}
/**
* @group store_v4
* @expectedException \InvalidArgumentException
*/
public function testInventoriesException()
{
$client = static::getApiClient(null, null, 'v4');
$client->request->storeInventoriesUpload([]);
}
/**
* @group store_v4
*/
public function testInventoriesUpload()
{
$client = static::getApiClient(null, null, 'v4');
$response = $client->request->storeInventoriesUpload([
[
'externalId' => 'pTKIKAeghYzX21HTdzFCe1',
'stores' => [
[
'code' => self::SCODE,
'available' => 10,
'purchasePrice' => 1700
]
]
],
[
'externalId' => 'JQIvcrCtiSpOV3AAfMiQB3',
'stores' => [
[
'code' => self::SCODE,
'available' => 20,
'purchasePrice' => 1500
]
]
],
]);
static::assertInstanceOf('RetailCrm\Response\ApiResponse', $response);
static::assertTrue($response->isSuccessful());
}
/**
* @group integration
*/
public function testInventoriesFailed()
{
$client = static::getApiClient(null, null, 'v4');
$externalIdA = 'upload-a-' . time();
$externalIdB = 'upload-b-' . time();
$response = $client->request->storeInventoriesUpload([
[
'externalId' => $externalIdA,
'available' => 10,
'purchasePrice' => 1700
],
[
'externalId' => $externalIdB,
'available' => 20,
'purchasePrice' => 1500
],
]);
static::assertInstanceOf('RetailCrm\Response\ApiResponse', $response);
static::assertEquals(400, $response->getStatusCode());
static::assertTrue(isset($response['errorMsg']), $response['errorMsg']);
}
/**
* @group store_v4
*/
public function testStoreProducts()
{
$client = static::getApiClient(null, null, 'v4');
$response = $client->request->storeProducts();
static::assertInstanceOf('RetailCrm\Response\ApiResponse', $response);
static::assertEquals(200, $response->getStatusCode());
static::assertTrue($response->isSuccessful());
}
}

View file

@ -12,7 +12,7 @@
* @link http://www.retailcrm.ru/docs/Developers/ApiVersion5
*/
namespace RetailCrm\Tests;
namespace RetailCrm\Tests\Methods\Version4;
use RetailCrm\Test\TestCase;
@ -27,7 +27,7 @@ use RetailCrm\Test\TestCase;
class ApiClientTelephonyTest extends TestCase
{
const TEL_CODE = 'telephony-code';
const TEL_CODE = 'telephony-code-v4';
const TEL_CLIENT = '123';
const TEL_IMAGE = 'http://www.mec.ph/horizon/wp-content/uploads/2011/11/telephony.svg';
@ -40,13 +40,13 @@ class ApiClientTelephonyTest extends TestCase
*/
public function testTelephonySettingsEdit()
{
$client = static::getApiClient();
$client = static::getApiClient(null, null, 'v4');
$response = $client->telephonySettingsEdit(
$response = $client->request->telephonySettingsEdit(
self::TEL_CODE,
self::TEL_CLIENT,
true,
'TestTelephony',
'TestTelephonyV4',
false,
self::TEL_IMAGE,
[['userId' => $_SERVER['CRM_USER_ID'], 'code' => '101']],
@ -67,9 +67,9 @@ class ApiClientTelephonyTest extends TestCase
*/
public function testTelephonySettingsGet()
{
$client = static::getApiClient();
$client = static::getApiClient(null, null, 'v4');
$response = $client->telephonySettingsGet(self::TEL_CODE);
$response = $client->request->telephonySettingsGet(self::TEL_CODE);
static::assertInstanceOf('RetailCrm\Response\ApiResponse', $response);
static::assertEquals(200, $response->getStatusCode());
static::assertTrue($response->isSuccessful());
@ -84,9 +84,9 @@ class ApiClientTelephonyTest extends TestCase
*/
public function testTelephonyEvent()
{
$client = static::getApiClient();
$client = static::getApiClient(null, null, 'v4');
$response = $client->telephonyCallEvent(
$response = $client->request->telephonyCallEvent(
'+79999999999',
'in',
['101'],
@ -109,9 +109,9 @@ class ApiClientTelephonyTest extends TestCase
*/
public function testTelephonyUpload()
{
$client = static::getApiClient();
$client = static::getApiClient(null, null, 'v4');
$response = $client->telephonyCallsUpload(
$response = $client->request->telephonyCallsUpload(
[
[
'date' => '2016-07-22 00:18:00',
@ -148,9 +148,9 @@ class ApiClientTelephonyTest extends TestCase
*/
public function testTelephonyManager()
{
$client = static::getApiClient();
$client = static::getApiClient(null, null, 'v4');
$response = $client->telephonyCallManager('+79999999999', 1);
$response = $client->request->telephonyCallManager('+79999999999', 1);
static::assertInstanceOf('RetailCrm\Response\ApiResponse', $response);
static::assertEquals(200, $response->getStatusCode());

View file

@ -12,7 +12,7 @@
* @link http://www.retailcrm.ru/docs/Developers/ApiVersion5
*/
namespace RetailCrm\Tests;
namespace RetailCrm\Tests\Methods\Version4;
use RetailCrm\Test\TestCase;
@ -28,39 +28,39 @@ use RetailCrm\Test\TestCase;
class ApiClientUsersTest extends TestCase
{
/**
* @group users
* @group users_v4
*/
public function testUsersGroups()
{
$client = static::getApiClient(null, null, "v4");
$response = $client->request->usersGroups();
static::assertInstanceOf('RetailCrm\Response\ApiResponse', $response);
static::assertTrue(in_array($response->getStatusCode(), [200, 201]));
static::assertTrue($response->isSuccessful());
}
/**
* @group users_v4
*/
public function testUsersList()
{
$client = static::getApiClient();
$client = static::getApiClient(null, null, "v4");
$response = $client->usersList();
$response = $client->request->usersList();
static::assertInstanceOf('RetailCrm\Response\ApiResponse', $response);
static::assertTrue(in_array($response->getStatusCode(), [200, 201]));
static::assertTrue($response->isSuccessful());
}
/**
* @group users
* @group users_v4
*/
public function testUsersGet()
{
$client = static::getApiClient();
$client = static::getApiClient(null, null, "v4");
$response = $client->usersGet($_SERVER["CRM_USER_ID"]);
static::assertInstanceOf('RetailCrm\Response\ApiResponse', $response);
static::assertTrue(in_array($response->getStatusCode(), [200, 201]));
static::assertTrue($response->isSuccessful());
}
/**
* @group users
*/
public function testUsersStatus()
{
$client = static::getApiClient();
$response = $client->usersStatus($_SERVER["CRM_USER_ID"], 'dinner');
$response = $client->request->usersGet($_SERVER["CRM_USER_ID"]);
static::assertInstanceOf('RetailCrm\Response\ApiResponse', $response);
static::assertTrue(in_array($response->getStatusCode(), [200, 201]));
static::assertTrue($response->isSuccessful());

View file

@ -12,10 +12,9 @@
* @link http://www.retailcrm.ru/docs/Developers/ApiVersion5
*/
namespace RetailCrm\Tests;
namespace RetailCrm\Tests\Methods\Version5;
use RetailCrm\Test\TestCase;
use function var_dump;
/**
* Class ApiClientCustomersTest
@ -31,7 +30,7 @@ class ApiClientCustomersTest extends TestCase
const FIRST_NAME = 'Иннокентий';
/**
* @group customers
* @group customers_v5
*/
public function testCustomersCreate()
{
@ -39,7 +38,7 @@ class ApiClientCustomersTest extends TestCase
$externalId = 'c-create-' . time();
$response = $client->customersCreate([
$response = $client->request->customersCreate([
'firstName' => self::FIRST_NAME,
'externalId' => $externalId,
]);
@ -55,17 +54,17 @@ class ApiClientCustomersTest extends TestCase
}
/**
* @group customers
* @group customers_v5
* @expectedException \InvalidArgumentException
*/
public function testCreateExceptionEmpty()
{
$client = static::getApiClient();
$client->customersCreate([]);
$client->request->customersCreate([]);
}
/**
* @group customers
* @group customers_v5
* @depends testCustomersCreate
*
* @param array $ids
@ -76,36 +75,36 @@ class ApiClientCustomersTest extends TestCase
{
$client = static::getApiClient();
$response = $client->customersGet(678678678);
$response = $client->request->customersGet(678678678);
static::assertInstanceOf('RetailCrm\Response\ApiResponse', $response);
static::assertEquals(404, $response->getStatusCode());
static::assertFalse($response->isSuccessful());
$response = $client->customersGet($ids['id'], 'id');
$response = $client->request->customersGet($ids['id'], 'id');
$customerById = $response['customer'];
static::assertInstanceOf('RetailCrm\Response\ApiResponse', $response);
static::assertEquals(200, $response->getStatusCode());
static::assertTrue($response->isSuccessful());
static::assertEquals(self::FIRST_NAME, $response['customer']['firstName']);
$response = $client->customersGet($ids['externalId'], 'externalId');
$response = $client->request->customersGet($ids['externalId'], 'externalId');
static::assertEquals($customerById['id'], $response['customer']['id']);
return $ids;
}
/**
* @group customers
* @group customers_v5
* @expectedException \InvalidArgumentException
*/
public function testCustomersGetException()
{
$client = static::getApiClient();
$client->customersGet(678678678, 'asdf');
$client->request->customersGet(678678678, 'asdf');
}
/**
* @group customers
* @group customers_v5
* @depends testCustomersGet
*
* @param array $ids
@ -114,7 +113,7 @@ class ApiClientCustomersTest extends TestCase
{
$client = static::getApiClient();
$response = $client->customersEdit(
$response = $client->request->customersEdit(
[
'id' => 22342134,
'lastName' => '12345',
@ -124,7 +123,7 @@ class ApiClientCustomersTest extends TestCase
static::assertInstanceOf('RetailCrm\Response\ApiResponse', $response);
static::assertEquals(404, $response->getStatusCode());
$response = $client->customersEdit([
$response = $client->request->customersEdit([
'externalId' => $ids['externalId'],
'lastName' => '12345',
]);
@ -134,45 +133,45 @@ class ApiClientCustomersTest extends TestCase
}
/**
* @group customers
* @group customers_v5
* @expectedException \InvalidArgumentException
*/
public function testCustomersEditExceptionEmpty()
{
$client = static::getApiClient();
$client->customersEdit([], 'asdf');
$client->request->customersEdit([], 'asdf');
}
/**
* @group customers
* @group customers_v5
* @expectedException \InvalidArgumentException
*/
public function testCustomersEditException()
{
$client = static::getApiClient();
$client->customersEdit(['id' => 678678678], 'asdf');
$client->request->customersEdit(['id' => 678678678], 'asdf');
}
/**
* @group customers
* @group customers_v5
*/
public function testCustomersList()
{
$client = static::getApiClient();
$response = $client->customersList();
$response = $client->request->customersList();
static::assertInstanceOf('RetailCrm\Response\ApiResponse', $response);
static::assertTrue($response->isSuccessful());
static::assertTrue(isset($response['customers']));
$response = $client->customersList([], 1, 300);
$response = $client->request->customersList([], 1, 300);
static::assertInstanceOf('RetailCrm\Response\ApiResponse', $response);
static::assertFalse(
$response->isSuccessful(),
'Pagination error'
);
$response = $client->customersList(['maxOrdersCount' => 10], 1);
$response = $client->request->customersList(['maxOrdersCount' => 10], 1);
static::assertInstanceOf('RetailCrm\Response\ApiResponse', $response);
static::assertTrue(
$response->isSuccessful(),
@ -181,23 +180,23 @@ class ApiClientCustomersTest extends TestCase
}
/**
* @group customers
* @group customers_v5
* @expectedException \InvalidArgumentException
*/
public function testCustomersFixExternalIdsException()
{
$client = static::getApiClient();
$client->customersFixExternalIds([]);
$client->request->customersFixExternalIds([]);
}
/**
* @group customers
* @group customers_v5
*/
public function testCustomersFixExternalIds()
{
$client = static::getApiClient();
$response = $client->ordersCreate([
$response = $client->request->ordersCreate([
'firstName' => 'Aaa111',
]);
@ -206,7 +205,7 @@ class ApiClientCustomersTest extends TestCase
'Order created'
);
$response = $client->ordersGet($response['id'], 'id');
$response = $client->request->ordersGet($response['id'], 'id');
static::assertTrue(
$response->isSuccessful(),
'Order fetched'
@ -215,7 +214,7 @@ class ApiClientCustomersTest extends TestCase
$id = $response['order']['customer']['id'];
$externalId = 'asdf' . time();
$response = $client->customersFixExternalIds([
$response = $client->request->customersFixExternalIds([
['id' => $id, 'externalId' => $externalId]
]);
@ -224,7 +223,7 @@ class ApiClientCustomersTest extends TestCase
'Fixed customer ids'
);
$response = $client->customersGet($externalId);
$response = $client->request->customersGet($externalId);
static::assertTrue(
$response->isSuccessful(),
'Got customer'
@ -242,17 +241,17 @@ class ApiClientCustomersTest extends TestCase
}
/**
* @group customers
* @group customers_v5
* @expectedException \InvalidArgumentException
*/
public function testCustomersUploadExceptionEmpty()
{
$client = static::getApiClient();
$client->customersUpload([]);
$client->request->customersUpload([]);
}
/**
* @group customers
* @group customers_v5
*/
public function testCustomersUpload()
{
@ -261,7 +260,7 @@ class ApiClientCustomersTest extends TestCase
$externalIdA = 'upload-a-' . time();
$externalIdB = 'upload-b-' . time();
$response = $client->customersUpload([
$response = $client->request->customersUpload([
[
'externalId' => $externalIdA,
'firstName' => 'Aaa',
@ -286,13 +285,13 @@ class ApiClientCustomersTest extends TestCase
}
/**
* @group customers
* @group customers_v5
*/
public function testCustomersCombine()
{
$client = static::getApiClient();
$responseCreateFirst = $client->customersCreate([
$responseCreateFirst = $client->request->customersCreate([
'firstName' => 'Aaa111',
'externalId' => 'AA-' . time(),
'phones' => [
@ -307,7 +306,7 @@ class ApiClientCustomersTest extends TestCase
'Got customer'
);
$responseCreateSecond = $client->customersCreate([
$responseCreateSecond = $client->request->customersCreate([
'firstName' => 'Aaa222',
'externalId' => 'BB-' . time(),
'phones' => [
@ -328,7 +327,7 @@ class ApiClientCustomersTest extends TestCase
$resultCustomer = ['id' => $responseCreateSecond['id']];
$response = $client->customersCombine($customers, $resultCustomer);
$response = $client->request->customersCombine($customers, $resultCustomer);
static::assertTrue(
$response->isSuccessful(),

View file

@ -0,0 +1,49 @@
<?php
/**
* PHP version 5.4
*
* API client marketplace test class
*
* @category RetailCrm
* @package RetailCrm
* @author RetailCrm <integration@retailcrm.ru>
* @license https://opensource.org/licenses/MIT MIT License
* @link http://www.retailcrm.ru/docs/Developers/ApiVersion5
*/
namespace RetailCrm\Tests\Methods\Version5;
use RetailCrm\Test\TestCase;
/**
* Class ApiClientMarketplaceTest
*
* @package RetailCrm\Tests
*/
class ApiClientMarketplaceTest extends TestCase
{
const SNAME = 'Marketplace integration v5';
const SCODE = 'integration_v5';
/**
* @group marketplace_v5
*/
public function testConfigurationEdit()
{
$client = static::getApiClient(null, null, "v5");
$response = $client->request->marketplaceSettingsEdit(
[
'name' => self::SNAME,
'code' => self::SCODE,
'logo' => 'http://download.retailcrm.pro/logos/setup.svg',
'active' => 'true'
]
);
static::assertInstanceOf('RetailCrm\Response\ApiResponse', $response);
static::assertTrue(in_array($response->getStatusCode(), [200, 201]));
static::assertTrue($response->isSuccessful());
}
}

View file

@ -12,7 +12,7 @@
* @link http://www.retailcrm.ru/docs/Developers/ApiVersion5
*/
namespace RetailCrm\Tests;
namespace RetailCrm\Tests\Methods\Version5;
use RetailCrm\Test\TestCase;
@ -30,15 +30,15 @@ class ApiClientOrdersTest extends TestCase
const FIRST_NAME = 'Иннокентий';
/**
* @group orders
* @group orders_v5
*/
public function testOrdersCreate()
{
$client = static::getApiClient();
$client = static::getApiClient(null, null, "v5");
$externalId = 'o-create-' . time();
$response = $client->ordersCreate([
$response = $client->request->ordersCreate([
'firstName' => self::FIRST_NAME,
'externalId' => $externalId,
]);
@ -53,13 +53,13 @@ class ApiClientOrdersTest extends TestCase
}
/**
* @group orders
* @group orders_v5
* @expectedException \InvalidArgumentException
*/
public function testOrdersCreateExceptionEmpty()
{
$client = static::getApiClient();
$client->ordersCreate([]);
$client = static::getApiClient(null, null, "v5");
$client->request->ordersCreate([]);
}
/**
@ -70,21 +70,21 @@ class ApiClientOrdersTest extends TestCase
*/
public function testOrdersStatuses(array $ids)
{
$client = static::getApiClient();
$client = static::getApiClient(null, null, "v5");
$response = $client->ordersStatuses();
$response = $client->request->ordersStatuses();
static::assertInstanceOf('RetailCrm\Response\ApiResponse', $response);
static::assertEquals(400, $response->getStatusCode());
static::assertFalse($response->isSuccessful());
$response = $client->ordersStatuses([], ['asdf']);
$response = $client->request->ordersStatuses([], ['asdf']);
static::assertInstanceOf('RetailCrm\Response\ApiResponse', $response);
static::assertEquals(200, $response->getStatusCode());
static::assertTrue($response->isSuccessful());
$orders = $response['orders'];
static::assertEquals(0, sizeof($orders));
$response = $client->ordersStatuses([], [$ids['externalId']]);
$response = $client->request->ordersStatuses([], [$ids['externalId']]);
static::assertInstanceOf('RetailCrm\Response\ApiResponse', $response);
static::assertEquals(200, $response->getStatusCode());
static::assertTrue($response->isSuccessful());
@ -92,14 +92,14 @@ class ApiClientOrdersTest extends TestCase
static::assertEquals(1, sizeof($orders));
static::assertEquals('new', $orders[0]['status']);
$response = $client->ordersStatuses([$ids['id']], [$ids['externalId']]);
$response = $client->request->ordersStatuses([$ids['id']], [$ids['externalId']]);
static::assertInstanceOf('RetailCrm\Response\ApiResponse', $response);
static::assertEquals(200, $response->getStatusCode());
static::assertTrue($response->isSuccessful());
$orders = $response['orders'];
static::assertEquals(1, sizeof($orders));
$response = $client->ordersStatuses([$ids['id']]);
$response = $client->request->ordersStatuses([$ids['id']]);
static::assertInstanceOf('RetailCrm\Response\ApiResponse', $response);
static::assertEquals(200, $response->getStatusCode());
static::assertTrue($response->isSuccessful());
@ -117,34 +117,34 @@ class ApiClientOrdersTest extends TestCase
*/
public function testOrdersGet(array $ids)
{
$client = static::getApiClient();
$client = static::getApiClient(null, null, "v5");
$response = $client->ordersGet(678678678);
$response = $client->request->ordersGet(678678678);
static::assertInstanceOf('RetailCrm\Response\ApiResponse', $response);
static::assertEquals(404, $response->getStatusCode());
static::assertFalse($response->isSuccessful());
$response = $client->ordersGet($ids['id'], 'id');
$response = $client->request->ordersGet($ids['id'], 'id');
$orderById = $response['order'];
static::assertInstanceOf('RetailCrm\Response\ApiResponse', $response);
static::assertEquals(200, $response->getStatusCode());
static::assertTrue($response->isSuccessful());
static::assertEquals(self::FIRST_NAME, $response['order']['firstName']);
$response = $client->ordersGet($ids['externalId'], 'externalId');
$response = $client->request->ordersGet($ids['externalId'], 'externalId');
static::assertEquals($orderById['id'], $response['order']['id']);
return $ids;
}
/**
* @group orders
* @group orders_v5
* @expectedException \InvalidArgumentException
*/
public function testOrdersGetException()
{
$client = static::getApiClient();
$client->ordersGet(678678678, 'asdf');
$client = static::getApiClient(null, null, "v5");
$client->request->ordersGet(678678678, 'asdf');
}
/**
@ -155,9 +155,9 @@ class ApiClientOrdersTest extends TestCase
*/
public function testOrdersEdit(array $ids)
{
$client = static::getApiClient();
$client = static::getApiClient(null, null, "v5");
$response = $client->ordersEdit(
$response = $client->request->ordersEdit(
[
'id' => 22342134,
'lastName' => '12345',
@ -167,7 +167,7 @@ class ApiClientOrdersTest extends TestCase
static::assertInstanceOf('RetailCrm\Response\ApiResponse', $response);
static::assertEquals(404, $response->getStatusCode());
$response = $client->ordersEdit([
$response = $client->request->ordersEdit([
'externalId' => $ids['externalId'],
'lastName' => '12345',
]);
@ -177,79 +177,79 @@ class ApiClientOrdersTest extends TestCase
}
/**
* @group orders
* @group orders_v5
* @expectedException \InvalidArgumentException
*/
public function testOrdersEditExceptionEmpty()
{
$client = static::getApiClient();
$client->ordersEdit([], 'asdf');
$client = static::getApiClient(null, null, "v5");
$client->request->ordersEdit([], 'asdf');
}
/**
* @group orders
* @group orders_v5
* @expectedException \InvalidArgumentException
*/
public function testOrdersEditException()
{
$client = static::getApiClient();
$client->ordersEdit(['id' => 678678678], 'asdf');
$client = static::getApiClient(null, null, "v5");
$client->request->ordersEdit(['id' => 678678678], 'asdf');
}
/**
* @group orders
* @group orders_v5
*/
public function testOrdersHistory()
{
$client = static::getApiClient();
$client = static::getApiClient(null, null, "v5");
$response = $client->ordersHistory();
$response = $client->request->ordersHistory();
static::assertInstanceOf('RetailCrm\Response\ApiResponse', $response);
static::assertEquals(200, $response->getStatusCode());
static::assertTrue($response->isSuccessful());
}
/**
* @group orders
* @group orders_v5
*/
public function testOrdersList()
{
$client = static::getApiClient();
$client = static::getApiClient(null, null, "v5");
$response = $client->ordersList();
$response = $client->request->ordersList();
static::assertInstanceOf('RetailCrm\Response\ApiResponse', $response);
static::assertTrue($response->isSuccessful());
static::assertTrue(isset($response['orders']));
$response = $client->ordersList([], 1, 300);
$response = $client->request->ordersList([], 1, 300);
static::assertInstanceOf('RetailCrm\Response\ApiResponse', $response);
static::assertFalse(
$response->isSuccessful(),
'Pagination error'
);
$response = $client->ordersList(['paymentStatus' => 'paid'], 1);
$response = $client->request->ordersList(['paymentStatus' => 'paid'], 1);
static::assertInstanceOf('RetailCrm\Response\ApiResponse', $response);
}
/**
* @group orders
* @group orders_v5
* @expectedException \InvalidArgumentException
*/
public function testOrdersFixExternalIdsException()
{
$client = static::getApiClient();
$client->ordersFixExternalIds([]);
$client = static::getApiClient(null, null, "v5");
$client->request->ordersFixExternalIds([]);
}
/**
* @group orders
* @group orders_v5
*/
public function testOrdersFixExternalIds()
{
$client = static::getApiClient();
$client = static::getApiClient(null, null, "v5");
$response = $client->ordersCreate([
$response = $client->request->ordersCreate([
'firstName' => 'Aaa',
]);
static::assertTrue(
@ -260,7 +260,7 @@ class ApiClientOrdersTest extends TestCase
$id = $response['id'];
$externalId = 'asdf' . time();
$response = $client->ordersFixExternalIds([
$response = $client->request->ordersFixExternalIds([
['id' => $id, 'externalId' => $externalId]
]);
@ -269,7 +269,7 @@ class ApiClientOrdersTest extends TestCase
'Fixed order ids'
);
$response = $client->ordersGet($externalId);
$response = $client->request->ordersGet($externalId);
static::assertTrue(
$response->isSuccessful(),
'Got order'
@ -287,26 +287,26 @@ class ApiClientOrdersTest extends TestCase
}
/**
* @group orders
* @group orders_v5
* @expectedException \InvalidArgumentException
*/
public function testOrdersUploadExceptionEmpty()
{
$client = static::getApiClient();
$client->ordersUpload([]);
$client = static::getApiClient(null, null, "v5");
$client->request->ordersUpload([]);
}
/**
* @group orders
* @group orders_v5
*/
public function testOrdersUpload()
{
$client = static::getApiClient();
$client = static::getApiClient(null, null, "v5");
$externalIdA = 'upload-a-' . time();
$externalIdB = 'upload-b-' . time();
$response = $client->ordersUpload([
$response = $client->request->ordersUpload([
[
'externalId' => $externalIdA,
'firstName' => 'Aaa',
@ -331,13 +331,13 @@ class ApiClientOrdersTest extends TestCase
}
/**
* @group orders
* @group orders_v5
*/
public function testOrdersCombine()
{
$client = static::getApiClient();
$client = static::getApiClient(null, null, "v5");
$responseCreateFirst = $client->ordersCreate([
$responseCreateFirst = $client->request->ordersCreate([
'firstName' => 'Aaa111',
'externalId' => 'AA-' . time(),
'phone' => '+79999999990'
@ -348,7 +348,7 @@ class ApiClientOrdersTest extends TestCase
'Got order'
);
$responseCreateSecond = $client->ordersCreate([
$responseCreateSecond = $client->request->ordersCreate([
'firstName' => 'Aaa222',
'externalId' => 'BB-' . time(),
'phone' => '+79999999991'
@ -362,7 +362,7 @@ class ApiClientOrdersTest extends TestCase
$order = ['id' => $responseCreateFirst['id']];
$resultOrder = ['id' => $responseCreateSecond['id']];
$response = $client->ordersCombine($order, $resultOrder, 'ours');
$response = $client->request->ordersCombine($order, $resultOrder, 'ours');
static::assertTrue(
$response->isSuccessful(),
@ -372,10 +372,10 @@ class ApiClientOrdersTest extends TestCase
public function testOrdersPayment()
{
$client = static::getApiClient();
$client = static::getApiClient(null, null, "v5");
$externalId = 'AA-' . time();
$responseCreateFirst = $client->ordersCreate([
$responseCreateFirst = $client->request->ordersCreate([
'firstName' => 'Aaa111aaA',
'phone' => '+79999999990'
]);
@ -394,7 +394,7 @@ class ApiClientOrdersTest extends TestCase
'status' => 'paid'
];
$response = $client->ordersPaymentCreate($payment);
$response = $client->request->ordersPaymentCreate($payment);
static::assertTrue(
$response->isSuccessful(),
@ -410,7 +410,7 @@ class ApiClientOrdersTest extends TestCase
'status' => 'paid'
];
$responseAgain = $client->ordersPaymentEdit($paymentEdit);
$responseAgain = $client->request->ordersPaymentEdit($paymentEdit);
static::assertTrue(
$responseAgain->isSuccessful(),

View file

@ -0,0 +1,68 @@
<?php
/**
* PHP version 5.4
*
* API client packs test class
*
* @category RetailCrm
* @package RetailCrm
* @author RetailCrm <integration@retailcrm.ru>
* @license https://opensource.org/licenses/MIT MIT License
* @link http://www.retailcrm.ru/docs/Developers/ApiVersion5
*/
namespace RetailCrm\Tests\Methods\Version5;
use RetailCrm\Test\TestCase;
/**
* Class ApiClientPacksTest
*
* @category RetailCrm
* @package RetailCrm
* @author RetailCrm <integration@retailcrm.ru>
* @license https://opensource.org/licenses/MIT MIT License
* @link http://www.retailcrm.ru/docs/Developers/ApiVersion5
*/
class ApiClientPacksTest extends TestCase
{
/**
* @group packs_v5
*/
public function testPacksHistory()
{
$client = static::getApiClient(null, null, "v5");
$response = $client->request->ordersPacksHistory();
static::assertInstanceOf('RetailCrm\Response\ApiResponse', $response);
static::assertEquals(200, $response->getStatusCode());
static::assertTrue($response->success);
static::assertTrue(
isset($response['history']),
'API returns orders assembly history'
);
static::assertTrue(
isset($response['generatedAt']),
'API returns generatedAt in orders assembly history'
);
}
/**
* @group packs_v5
*/
public function testPacksCreateFailed()
{
$client = static::getApiClient(null, null, "v5");
$pack = [
'itemId' => 12,
'store' => 'test',
'quantity' => 2
];
$response = $client->request->ordersPacksCreate($pack);
static::assertInstanceOf('RetailCrm\Response\ApiResponse', $response);
static::assertEquals(400, $response->getStatusCode());
static::assertFalse($response->success);
}
}

View file

@ -0,0 +1,114 @@
<?php
/**
* PHP version 5.4
*
* API client prices test class
*
* @category RetailCrm
* @package RetailCrm
* @author RetailCrm <integration@retailcrm.ru>
* @license https://opensource.org/licenses/MIT MIT License
* @link http://www.retailcrm.ru/docs/Developers/ApiVersion5
*/
namespace RetailCrm\Tests\Methods\Version5;
use RetailCrm\Test\TestCase;
/**
* Class ApiClientPricesTest
*
* @category RetailCrm
* @package RetailCrm
* @author RetailCrm <integration@retailcrm.ru>
* @license https://opensource.org/licenses/MIT MIT License
* @link http://www.retailcrm.ru/docs/Developers/ApiVersion5
*/
class ApiClientPricesTest extends TestCase
{
/**
* @group prices_v5
*/
public function testPricesEdit()
{
$client = static::getApiClient(null, null, "v5");
$response = $client->request->pricesTypesEdit(
[
'code' => 'sample_v4_price_code',
'name' => 'Sample v4 price type',
'ordering' => 500,
'active' => true
]
);
static::assertInstanceOf('RetailCrm\Response\ApiResponse', $response);
static::assertEquals(200, $response->getStatusCode());
static::assertTrue($response->isSuccessful());
}
/**
* @depends testPricesEdit
* @group prices_v5
*/
public function testPricesGet()
{
$client = static::getApiClient(null, null, "v5");
$response = $client->request->pricesTypes();
static::assertInstanceOf('RetailCrm\Response\ApiResponse', $response);
static::assertTrue(in_array($response->getStatusCode(), [200, 201]));
static::assertTrue($response->isSuccessful());
}
/**
* @group prices_v5
* @expectedException \InvalidArgumentException
*/
public function testPricesUploadExceptionEmpty()
{
$client = static::getApiClient(null, null, "v5");
$client->request->storePricesUpload([]);
}
/**
* @depends testPricesEdit
* @group prices_v5
*/
public function testPricesUpload()
{
$client = static::getApiClient(null, null, "v5");
$xmlIdA = 'upload-a-' . time();
$xmlIdB = 'upload-b-' . time();
$response = $client->request->storePricesUpload([
[
'xmlId' => $xmlIdA,
'prices' => [
[
'code' => 'sample_v4_price_code',
'price' => 1700
]
]
],
[
'xmlId' => $xmlIdB,
'prices' => [
[
'code' => 'sample_v4_price_code',
'price' => 1500
]
]
],
]);
static::assertInstanceOf('RetailCrm\Response\ApiResponse', $response);
static::assertEquals(200, $response->getStatusCode());
}
}

View file

@ -0,0 +1,171 @@
<?php
/**
* PHP version 5.4
*
* API client references test class
*
* @category RetailCrm
* @package RetailCrm
* @author RetailCrm <integration@retailcrm.ru>
* @license https://opensource.org/licenses/MIT MIT License
* @link http://www.retailcrm.ru/docs/Developers/ApiVersion5
*/
namespace RetailCrm\Tests\Methods\Version5;
use RetailCrm\Test\TestCase;
/**
* Class ApiClientReferenceTest
*
* @category RetailCrm
* @package RetailCrm
* @author RetailCrm <integration@retailcrm.ru>
* @license https://opensource.org/licenses/MIT MIT License
* @link http://www.retailcrm.ru/docs/Developers/ApiVersion5
*/
class ApiClientReferenceTest extends TestCase
{
/**
* @group reference_v5
* @dataProvider getListDictionaries
* @param $name
*/
public function testList($name)
{
$client = static::getApiClient(null, null, "v5");
$method = $name . 'List';
$response = $client->request->$method();
/* @var \RetailCrm\Response\ApiResponse $response */
static::assertInstanceOf('RetailCrm\Response\ApiResponse', $response);
static::assertTrue($response->isSuccessful());
static::assertTrue(isset($response[$name]));
static::assertTrue(is_array($response[$name]));
}
/**
* @group reference_v5
* @dataProvider getEditDictionaries
* @expectedException \InvalidArgumentException
*
* @param $name
*/
public function testEditingException($name)
{
$client = static::getApiClient(null, null, "v5");
$method = $name . 'Edit';
$client->request->$method([]);
}
/**
* @group reference_v5
* @dataProvider getEditDictionaries
*
* @param $name
*/
public function testEditing($name)
{
$client = static::getApiClient(null, null, "v5");
$code = 'dict-' . strtolower($name) . '-' . time();
$method = $name . 'Edit';
$params = [
'code' => $code,
'name' => 'Aaa' . $code,
'active' => false
];
if ($name == 'statuses') {
$params['group'] = 'new';
}
$response = $client->request->$method($params);
/* @var \RetailCrm\Response\ApiResponse $response */
static::assertTrue(in_array($response->getStatusCode(), [200, 201]));
$response = $client->request->$method([
'code' => $code,
'name' => 'Bbb' . $code,
'active' => false
]);
static::assertTrue(in_array($response->getStatusCode(), [200, 201]));
}
/**
* @group reference_v5
* @group site
*/
public function testSiteEditing()
{
$name = 'sites';
$client = static::getApiClient(null, null, "v5");
$code = 'dict-' . strtolower($name) . '-' . time();
$method = $name . 'Edit';
$params = [
'code' => $code,
'name' => 'Aaa',
'active' => false
];
$response = $client->request->$method($params);
/* @var \RetailCrm\Response\ApiResponse $response */
static::assertEquals(400, $response->getStatusCode());
if ($code == $client->request->getSite()) {
$method = $name . 'Edit';
$params = [
'code' => $code,
'name' => 'Aaa' . time(),
'active' => false
];
$response = $client->request->$method($params);
static::assertEquals(200, $response->getStatusCode());
}
}
/**
* @return array
*/
public function getListDictionaries()
{
return [
['deliveryServices'],
['deliveryTypes'],
['orderMethods'],
['orderTypes'],
['paymentStatuses'],
['paymentTypes'],
['productStatuses'],
['statusGroups'],
['statuses'],
['sites'],
['stores'],
];
}
/**
* @return array
*/
public function getEditDictionaries()
{
return [
['deliveryServices'],
['deliveryTypes'],
['orderMethods'],
['orderTypes'],
['paymentStatuses'],
['paymentTypes'],
['productStatuses'],
['statuses'],
];
}
}

View file

@ -12,7 +12,7 @@
* @link http://www.retailcrm.ru/docs/Developers/ApiVersion5
*/
namespace RetailCrm\Tests;
namespace RetailCrm\Tests\Methods\Version5;
use RetailCrm\Test\TestCase;
@ -27,30 +27,30 @@ use RetailCrm\Test\TestCase;
*/
class ApiClientStoreTest extends TestCase
{
const SNAME = 'Test Store';
const SCODE = 'test-store';
const SNAME = 'Test Store V5';
const SCODE = 'test-store-v5';
/**
* @group store
* @group store_v4
*/
public function testStoreCreate()
{
$client = static::getApiClient();
$client = static::getApiClient(null, null, "v5");
$response = $client->storesEdit(['name' => self::SNAME, 'code' => self::SCODE]);
$response = $client->request->storesEdit(['name' => self::SNAME, 'code' => self::SCODE]);
static::assertInstanceOf('RetailCrm\Response\ApiResponse', $response);
static::assertTrue(in_array($response->getStatusCode(), [200, 201]));
static::assertTrue($response->isSuccessful());
}
/**
* @group store
* @group store_v4
*/
public function testStoreInventories()
{
$client = static::getApiClient();
$client = static::getApiClient(null, null, "v5");
$response = $client->storeInventories();
$response = $client->request->storeInventories();
static::assertInstanceOf('RetailCrm\Response\ApiResponse', $response);
static::assertEquals(200, $response->getStatusCode());
static::assertTrue($response->isSuccessful());
@ -61,23 +61,23 @@ class ApiClientStoreTest extends TestCase
}
/**
* @group store
* @group store_v4
* @expectedException \InvalidArgumentException
*/
public function testInventoriesException()
{
$client = static::getApiClient();
$client->storeInventoriesUpload([]);
$client = static::getApiClient(null, null, "v5");
$client->request->storeInventoriesUpload([]);
}
/**
* @group store
* @group store_v4
*/
public function testInventoriesUpload()
{
$client = static::getApiClient();
$client = static::getApiClient(null, null, "v5");
$response = $client->storeInventoriesUpload([
$response = $client->request->storeInventoriesUpload([
[
'externalId' => 'pTKIKAeghYzX21HTdzFCe1',
'stores' => [
@ -109,12 +109,12 @@ class ApiClientStoreTest extends TestCase
*/
public function testInventoriesFailed()
{
$client = static::getApiClient();
$client = static::getApiClient(null, null, "v5");
$externalIdA = 'upload-a-' . time();
$externalIdB = 'upload-b-' . time();
$response = $client->storeInventoriesUpload([
$response = $client->request->storeInventoriesUpload([
[
'externalId' => $externalIdA,
'available' => 10,
@ -132,26 +132,26 @@ class ApiClientStoreTest extends TestCase
}
/**
* @group store
* @group store_v4
*/
public function testStoreProducts()
{
$client = static::getApiClient();
$client = static::getApiClient(null, null, "v5");
$response = $client->storeProducts();
$response = $client->request->storeProducts();
static::assertInstanceOf('RetailCrm\Response\ApiResponse', $response);
static::assertEquals(200, $response->getStatusCode());
static::assertTrue($response->isSuccessful());
}
/**
* @group store
* @group store_v4
*/
public function testStoreProductsGroups()
{
$client = static::getApiClient();
$client = static::getApiClient(null, null, "v5");
$response = $client->storeProductsGroups();
$response = $client->request->storeProductsGroups();
static::assertInstanceOf('RetailCrm\Response\ApiResponse', $response);
static::assertEquals(200, $response->getStatusCode());
static::assertTrue($response->isSuccessful());

View file

@ -12,7 +12,7 @@
* @link http://www.retailcrm.ru/docs/Developers/ApiVersion5
*/
namespace RetailCrm\Tests;
namespace RetailCrm\Tests\Methods\Version5;
use RetailCrm\Test\TestCase;
@ -28,31 +28,31 @@ use RetailCrm\Test\TestCase;
class ApiClientTasksTest extends TestCase
{
/**
* @group tasks
* @group tasks_v5
*/
public function testTasksList()
{
$client = static::getApiClient();
$client = static::getApiClient(null, null, 'v5');
$response = $client->tasksList();
$response = $client->request->tasksList();
static::assertInstanceOf('RetailCrm\Response\ApiResponse', $response);
static::assertEquals(200, $response->getStatusCode());
}
/**
* @group tasks
* @group tasks_v5
* @expectedException \InvalidArgumentException
*/
public function testTasksCreateExceptionEmpty()
{
$client = static::getApiClient();
$client->tasksCreate([]);
$client = static::getApiClient(null, null, 'v5');
$client->request->tasksCreate([]);
}
public function testTasksCRU()
{
$client = static::getApiClient();
$client = static::getApiClient(null, null, 'v5');
$task = [
'text' => 'test task',
@ -61,14 +61,14 @@ class ApiClientTasksTest extends TestCase
'complete' => false
];
$responseCreate = $client->tasksCreate($task);
$responseCreate = $client->request->tasksCreate($task);
static::assertInstanceOf('RetailCrm\Response\ApiResponse', $responseCreate);
static::assertEquals(201, $responseCreate->getStatusCode());
$uid = $responseCreate['id'];
$responseRead = $client->tasksGet($uid);
$responseRead = $client->request->tasksGet($uid);
static::assertInstanceOf('RetailCrm\Response\ApiResponse', $responseRead);
static::assertEquals(200, $responseRead->getStatusCode());
@ -76,7 +76,7 @@ class ApiClientTasksTest extends TestCase
$task['id'] = $uid;
$task['complete'] = true;
$responseUpdate = $client->tasksEdit($task);
$responseUpdate = $client->request->tasksEdit($task);
static::assertInstanceOf('RetailCrm\Response\ApiResponse', $responseUpdate);
static::assertEquals(200, $responseUpdate->getStatusCode());

View file

@ -0,0 +1,159 @@
<?php
/**
* PHP version 5.4
*
* API client telephony test class
*
* @category RetailCrm
* @package RetailCrm
* @author RetailCrm <integration@retailcrm.ru>
* @license https://opensource.org/licenses/MIT MIT License
* @link http://www.retailcrm.ru/docs/Developers/ApiVersion5
*/
namespace RetailCrm\Tests\Methods\Version5;
use RetailCrm\Test\TestCase;
/**
* Class ApiClientTelephonyTest
* @category RetailCrm
* @package RetailCrm\Tests
* @author RetailCrm <integration@retailcrm.ru>
* @license https://opensource.org/licenses/MIT MIT License
* @link http://www.retailcrm.ru/docs/Developers/ApiVersion5
*/
class ApiClientTelephonyTest extends TestCase
{
const TEL_CODE = 'telephony-code-v5';
const TEL_CLIENT = '456';
const TEL_IMAGE = 'http://www.mec.ph/horizon/wp-content/uploads/2011/11/telephony.svg';
/**
* Settings Edit test
*
* @group telephony
*
* @return void
*/
public function testTelephonySettingsEdit()
{
$client = static::getApiClient(null, null, "v5");
$response = $client->request->telephonySettingsEdit(
self::TEL_CODE,
self::TEL_CLIENT,
true,
'TestTelephonyV5',
false,
self::TEL_IMAGE,
[['userId' => $_SERVER['CRM_USER_ID'], 'code' => '101']],
[['siteCode' => 'api-client-php', 'externalPhone' => '+74950000000']]
);
static::assertInstanceOf('RetailCrm\Response\ApiResponse', $response);
static::assertTrue(in_array($response->getStatusCode(), [200, 201]));
static::assertTrue($response->isSuccessful());
}
/**
* Settings Get test
*
* @group telephony
*
* @return void
*/
public function testTelephonySettingsGet()
{
$client = static::getApiClient(null, null, "v5");
$response = $client->request->telephonySettingsGet(self::TEL_CODE);
static::assertInstanceOf('RetailCrm\Response\ApiResponse', $response);
static::assertEquals(200, $response->getStatusCode());
static::assertTrue($response->isSuccessful());
}
/**
* Event test
*
* @group telephony
*
* @return void
*/
public function testTelephonyEvent()
{
$client = static::getApiClient(null, null, "v5");
$response = $client->request->telephonyCallEvent(
'+79999999999',
'in',
['101'],
'failed',
'+74950000000'
);
static::assertInstanceOf('RetailCrm\Response\ApiResponse', $response);
static::assertEquals(200, $response->getStatusCode());
static::assertTrue($response->isSuccessful());
}
/**
* Upload test
*
* @group telephony
*
* @return void
*/
public function testTelephonyUpload()
{
$client = static::getApiClient(null, null, "v5");
$response = $client->request->telephonyCallsUpload(
[
[
'date' => '2016-07-22 00:18:00',
'type' => 'in',
'phone' => '+79999999999',
'code' => '101',
'result' => 'answered',
'externalId' => rand(10, 100),
'recordUrl' => 'http://download.retailcrm.pro/api-client-files/beep1.mp3'
],
[
'date' => '2016-07-22 00:24:00',
'type' => 'in',
'phone' => '+79999999999',
'code' => '101',
'result' => 'answered',
'externalId' => rand(10, 100),
'recordUrl' => 'http://download.retailcrm.pro/api-client-files/beep2.mp3'
]
]
);
static::assertInstanceOf('RetailCrm\Response\ApiResponse', $response);
static::assertEquals(200, $response->getStatusCode());
static::assertTrue($response->isSuccessful());
}
/**
* Manager test
*
* @group telephony
*
* @return void
*/
public function testTelephonyManager()
{
$client = static::getApiClient(null, null, "v5");
$response = $client->request->telephonyCallManager('+79999999999', 1);
static::assertInstanceOf('RetailCrm\Response\ApiResponse', $response);
static::assertEquals(200, $response->getStatusCode());
static::assertTrue($response->isSuccessful());
}
}

View file

@ -0,0 +1,81 @@
<?php
/**
* PHP version 5.4
*
* API client users test class
*
* @category RetailCrm
* @package RetailCrm
* @author RetailCrm <integration@retailcrm.ru>
* @license https://opensource.org/licenses/MIT MIT License
* @link http://www.retailcrm.ru/docs/Developers/ApiVersion5
*/
namespace RetailCrm\Tests\Methods\Version5;
use RetailCrm\Test\TestCase;
/**
* Class ApiClientUsersTest
*
* @category RetailCrm
* @package RetailCrm
* @author RetailCrm <integration@retailcrm.ru>
* @license https://opensource.org/licenses/MIT MIT License
* @link http://www.retailcrm.ru/docs/Developers/ApiVersion5
*/
class ApiClientUsersTest extends TestCase
{
/**
* @group users_v5
*/
public function testUsersGroups()
{
$client = static::getApiClient(null, null, "v5");
$response = $client->request->usersGroups();
static::assertInstanceOf('RetailCrm\Response\ApiResponse', $response);
static::assertTrue(in_array($response->getStatusCode(), [200, 201]));
static::assertTrue($response->isSuccessful());
}
/**
* @group users_v5
*/
public function testUsersList()
{
$client = static::getApiClient(null, null, "v5");
$response = $client->request->usersList();
static::assertInstanceOf('RetailCrm\Response\ApiResponse', $response);
static::assertTrue(in_array($response->getStatusCode(), [200, 201]));
static::assertTrue($response->isSuccessful());
}
/**
* @group users_v5
*/
public function testUsersGet()
{
$client = static::getApiClient(null, null, "v5");
$response = $client->request->usersGet($_SERVER["CRM_USER_ID"]);
static::assertInstanceOf('RetailCrm\Response\ApiResponse', $response);
static::assertTrue(in_array($response->getStatusCode(), [200, 201]));
static::assertTrue($response->isSuccessful());
}
/**
* @group users_v5
*/
public function testUsersStatus()
{
$client = static::getApiClient(null, null, "v5");
$response = $client->request->usersStatus($_SERVER["CRM_USER_ID"], 'dinner');
static::assertInstanceOf('RetailCrm\Response\ApiResponse', $response);
static::assertTrue(in_array($response->getStatusCode(), [200, 201]));
static::assertTrue($response->isSuccessful());
}
}

View file

@ -29,19 +29,19 @@ use RetailCrm\Response\ApiResponse;
class ApiResponseTest extends TestCase
{
/**
* @group unit
* @group response
*/
public function testSuccessConstruct()
{
$response = new ApiResponse(200);
$this->assertInstanceOf(
static::assertInstanceOf(
'RetailCrm\Response\ApiResponse',
$response,
'Response object created'
);
$response = new ApiResponse(201, '{ "success": true }');
$this->assertInstanceOf(
static::assertInstanceOf(
'RetailCrm\Response\ApiResponse',
$response,
'Response object created'
@ -49,28 +49,28 @@ class ApiResponseTest extends TestCase
}
/**
* @group unit
* @group response
* @expectedException \RetailCrm\Exception\InvalidJsonException
*/
public function testJsonInvalid()
{
$response = new ApiResponse(400, '{ "asdf": }');
new ApiResponse(400, '{ "asdf": }');
}
/**
* @group unit
* @group response
*/
public function testStatusCodeGetting()
{
$response = new ApiResponse(200);
$this->assertEquals(
static::assertEquals(
200,
$response->getStatusCode(),
'Response object returns the right status code'
);
$response = new ApiResponse(460, '{ "success": false }');
$this->assertEquals(
static::assertEquals(
460,
$response->getStatusCode(),
'Response object returns the right status code'
@ -78,38 +78,38 @@ class ApiResponseTest extends TestCase
}
/**
* @group unit
* @group response
*/
public function testIsSuccessful()
{
$response = new ApiResponse(200);
$this->assertTrue(
static::assertTrue(
$response->isSuccessful(),
'Request was successful'
);
$response = new ApiResponse(460, '{ "success": false }');
$this->assertFalse(
static::assertFalse(
$response->isSuccessful(),
'Request was failed'
);
}
/**
* @group unit
* @group response
*/
public function testMagicCall()
{
$response = new ApiResponse(201, '{ "success": true }');
$this->assertEquals(
static::assertEquals(
true,
$response->getSuccess(),
$response->isSuccessful(),
'Response object returns property value throw magic method'
);
}
/**
* @group unit
* @group response
* @expectedException \InvalidArgumentException
*/
public function testMagicCallException1()
@ -119,7 +119,7 @@ class ApiResponseTest extends TestCase
}
/**
* @group unit
* @group response
* @expectedException \InvalidArgumentException
*/
public function testMagicCallException2()
@ -129,12 +129,12 @@ class ApiResponseTest extends TestCase
}
/**
* @group unit
* @group response
*/
public function testMagicGet()
{
$response = new ApiResponse(201, '{ "success": true }');
$this->assertEquals(
static::assertEquals(
true,
$response->success,
'Response object returns property value throw magic get'
@ -142,7 +142,7 @@ class ApiResponseTest extends TestCase
}
/**
* @group unit
* @group response
* @expectedException \InvalidArgumentException
*/
public function testMagicGetException1()
@ -152,7 +152,7 @@ class ApiResponseTest extends TestCase
}
/**
* @group unit
* @group response
* @expectedException \InvalidArgumentException
*/
public function testMagicGetException2()
@ -162,12 +162,12 @@ class ApiResponseTest extends TestCase
}
/**
* @group unit
* @group response
*/
public function testArrayGet()
{
$response = new ApiResponse(201, '{ "success": true }');
$this->assertEquals(
static::assertEquals(
true,
$response['success'],
'Response object returns property value throw magic array get'
@ -175,7 +175,7 @@ class ApiResponseTest extends TestCase
}
/**
* @group unit
* @group response
* @expectedException \InvalidArgumentException
*/
public function testArrayGetException1()
@ -185,7 +185,7 @@ class ApiResponseTest extends TestCase
}
/**
* @group unit
* @group response
* @expectedException \InvalidArgumentException
*/
public function testArrayGetException2()
@ -195,25 +195,25 @@ class ApiResponseTest extends TestCase
}
/**
* @group unit
* @group response
*/
public function testArrayIsset()
{
$response = new ApiResponse(201, '{ "success": true }');
$this->assertTrue(
static::assertTrue(
isset($response['success']),
'Response object returns property existing'
);
$this->assertFalse(
static::assertFalse(
isset($response['suess']),
'Response object returns property existing'
);
}
/**
* @group unit
* @group response
* @expectedException \BadMethodCallException
*/
public function testArraySetException1()
@ -223,7 +223,7 @@ class ApiResponseTest extends TestCase
}
/**
* @group unit
* @group response
* @expectedException \BadMethodCallException
*/
public function testArraySetException2()
@ -233,7 +233,7 @@ class ApiResponseTest extends TestCase
}
/**
* @group unit
* @group response
* @expectedException \BadMethodCallException
*/
public function testArrayUnsetException1()
@ -243,7 +243,7 @@ class ApiResponseTest extends TestCase
}
/**
* @group unit
* @group response
* @expectedException \BadMethodCallException
*/
public function testArrayUnsetException2()
@ -253,18 +253,18 @@ class ApiResponseTest extends TestCase
}
/**
* @group unit
* @group response
*/
public function testMagicIsset()
{
$response = new ApiResponse(201, '{ "success": true }');
$this->assertTrue(
static::assertTrue(
isset($response->success),
'Response object returns property existing'
);
$this->assertFalse(
static::assertFalse(
isset($response->suess),
'Response object returns property existing'
);