2014-11-06 02:44:52 +03:00
|
|
|
<?php
|
|
|
|
|
2017-06-22 00:55:08 +03:00
|
|
|
/**
|
|
|
|
* PHP version 5.4
|
|
|
|
*
|
|
|
|
* Test case class
|
|
|
|
*
|
|
|
|
* @category RetailCrm
|
|
|
|
* @package RetailCrm
|
|
|
|
* @author RetailCrm <integration@retailcrm.ru>
|
|
|
|
* @license https://opensource.org/licenses/MIT MIT License
|
2019-08-30 14:10:52 +03:00
|
|
|
* @link https://help.retailcrm.ru/Developers/ApiVersion5
|
2017-06-22 00:55:08 +03:00
|
|
|
*/
|
|
|
|
|
2014-11-06 02:44:52 +03:00
|
|
|
namespace RetailCrm\Test;
|
|
|
|
|
2020-09-09 12:51:31 +03:00
|
|
|
use PHPUnit\Framework\MockObject\MockObject;
|
2014-11-06 02:44:52 +03:00
|
|
|
use RetailCrm\ApiClient;
|
2015-05-04 18:47:14 +03:00
|
|
|
use RetailCrm\Http\Client;
|
2019-08-30 14:10:52 +03:00
|
|
|
use PHPUnit\Framework\TestCase as BaseCase;
|
2014-11-06 02:44:52 +03:00
|
|
|
|
2017-06-22 00:55:08 +03:00
|
|
|
/**
|
|
|
|
* Class TestCase
|
|
|
|
*
|
2018-01-10 11:35:57 +03:00
|
|
|
* @category RetailCrm
|
|
|
|
* @package RetailCrm
|
|
|
|
* @author RetailCrm <integration@retailcrm.ru>
|
|
|
|
* @license https://opensource.org/licenses/MIT MIT License
|
2019-08-30 14:10:52 +03:00
|
|
|
* @link https://help.retailcrm.ru/Developers/ApiVersion5
|
2017-06-22 00:55:08 +03:00
|
|
|
*/
|
2019-08-30 14:10:52 +03:00
|
|
|
class TestCase extends BaseCase
|
2014-11-06 02:44:52 +03:00
|
|
|
{
|
|
|
|
/**
|
|
|
|
* Return ApiClient object
|
|
|
|
*
|
2018-01-10 11:35:57 +03:00
|
|
|
* @param string $url (default: null)
|
|
|
|
* @param string $apiKey (default: null)
|
|
|
|
* @param string $version (default: null)
|
|
|
|
* @param string $site (default: null)
|
2017-06-22 00:55:08 +03:00
|
|
|
*
|
2014-11-06 02:44:52 +03:00
|
|
|
* @return ApiClient
|
|
|
|
*/
|
2018-01-10 11:35:57 +03:00
|
|
|
public static function getApiClient(
|
|
|
|
$url = null,
|
|
|
|
$apiKey = null,
|
|
|
|
$version = null,
|
|
|
|
$site = null
|
|
|
|
) {
|
2018-02-20 17:50:45 +03:00
|
|
|
$configUrl = getenv('RETAILCRM_URL') ?: $_SERVER['RETAILCRM_URL'];
|
|
|
|
$configKey = getenv('RETAILCRM_KEY') ?: $_SERVER['RETAILCRM_KEY'];
|
|
|
|
$configVersion = getenv('RETAILCRM_VERSION') ?: $_SERVER['RETAILCRM_VERSION'];
|
|
|
|
$configSite = getenv('RETAILCRM_SITE') ?: $_SERVER['RETAILCRM_SITE'];
|
2017-06-22 00:55:08 +03:00
|
|
|
|
2014-11-27 11:23:44 +03:00
|
|
|
return new ApiClient(
|
2017-06-22 00:55:08 +03:00
|
|
|
$url ?: $configUrl,
|
|
|
|
$apiKey ?: $configKey,
|
|
|
|
$version ?: $configVersion,
|
2018-02-20 17:50:45 +03:00
|
|
|
$site ?: $configSite
|
2014-11-27 11:23:44 +03:00
|
|
|
);
|
2014-11-06 02:44:52 +03:00
|
|
|
}
|
2016-11-28 14:38:03 +03:00
|
|
|
|
2020-09-09 12:51:31 +03:00
|
|
|
/**
|
|
|
|
* @param \RetailCrm\Http\Client|MockObject $httpClient
|
|
|
|
* @return ApiClient
|
|
|
|
* @throws \ReflectionException
|
|
|
|
*/
|
|
|
|
public static function getMockedApiClient($httpClient)
|
|
|
|
{
|
|
|
|
$client = self::getApiClient();
|
|
|
|
$property = new \ReflectionProperty(get_class($client->request), 'client');
|
|
|
|
|
|
|
|
$property->setAccessible(true);
|
|
|
|
$property->setValue($client->request, $httpClient);
|
|
|
|
|
|
|
|
return $client;
|
|
|
|
}
|
|
|
|
|
2015-05-04 18:47:14 +03:00
|
|
|
/**
|
|
|
|
* Return Client object
|
|
|
|
*
|
2018-01-10 11:35:57 +03:00
|
|
|
* @param string $url (default: null)
|
|
|
|
* @param array $defaultParameters (default: array())
|
2016-03-12 01:54:33 +03:00
|
|
|
*
|
2015-05-04 18:47:14 +03:00
|
|
|
* @return Client
|
|
|
|
*/
|
2017-06-22 00:55:08 +03:00
|
|
|
public static function getClient($url = null, $defaultParameters = [])
|
2015-05-04 18:47:14 +03:00
|
|
|
{
|
2018-02-20 17:50:45 +03:00
|
|
|
$configUrl = getenv('RETAILCRM_URL') ?: $_SERVER['RETAILCRM_URL'];
|
|
|
|
$configKey = getenv('RETAILCRM_KEY') ?: $_SERVER['RETAILCRM_KEY'];
|
|
|
|
$configVersion = getenv('RETAILCRM_VERSION') ?: $_SERVER['RETAILCRM_VERSION'];
|
2017-06-22 00:55:08 +03:00
|
|
|
|
2015-05-04 18:47:14 +03:00
|
|
|
return new Client(
|
2018-02-20 17:50:45 +03:00
|
|
|
$url ?: $configUrl . '/api/' . $configVersion,
|
2017-06-22 00:55:08 +03:00
|
|
|
[
|
2016-03-12 01:54:33 +03:00
|
|
|
'apiKey' => array_key_exists('apiKey', $defaultParameters)
|
|
|
|
? $defaultParameters['apiKey']
|
2018-02-20 17:50:45 +03:00
|
|
|
: $configKey
|
2017-06-22 00:55:08 +03:00
|
|
|
]
|
2015-05-04 18:47:14 +03:00
|
|
|
);
|
|
|
|
}
|
|
|
|
}
|