1
0
mirror of synced 2024-11-23 13:56:06 +03:00
api-client-php/tests/RetailCrm/Test/TestCase.php

85 lines
2.4 KiB
PHP
Raw Normal View History

<?php
/**
* 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
*/
namespace RetailCrm\Test;
use RetailCrm\ApiClient;
use RetailCrm\Http\Client;
2019-08-30 14:10:52 +03:00
use PHPUnit\Framework\TestCase as BaseCase;
/**
* 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
*/
2019-08-30 14:10:52 +03:00
class TestCase extends BaseCase
{
/**
* 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)
*
* @return ApiClient
*/
2018-01-10 11:35:57 +03:00
public static function getApiClient(
$url = null,
$apiKey = null,
$version = null,
$site = null
) {
$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'];
return new ApiClient(
$url ?: $configUrl,
$apiKey ?: $configKey,
$version ?: $configVersion,
$site ?: $configSite
);
}
/**
* 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
*
* @return Client
*/
public static function getClient($url = null, $defaultParameters = [])
{
$configUrl = getenv('RETAILCRM_URL') ?: $_SERVER['RETAILCRM_URL'];
$configKey = getenv('RETAILCRM_KEY') ?: $_SERVER['RETAILCRM_KEY'];
$configVersion = getenv('RETAILCRM_VERSION') ?: $_SERVER['RETAILCRM_VERSION'];
return new Client(
$url ?: $configUrl . '/api/' . $configVersion,
[
2016-03-12 01:54:33 +03:00
'apiKey' => array_key_exists('apiKey', $defaultParameters)
? $defaultParameters['apiKey']
: $configKey
]
);
}
}