2014-11-06 02:44:52 +03:00
|
|
|
<?php
|
|
|
|
|
|
|
|
namespace RetailCrm\Test;
|
|
|
|
|
|
|
|
use RetailCrm\ApiClient;
|
2015-05-04 18:47:14 +03:00
|
|
|
use RetailCrm\Http\Client;
|
2014-11-06 02:44:52 +03:00
|
|
|
|
|
|
|
class TestCase extends \PHPUnit_Framework_TestCase
|
|
|
|
{
|
|
|
|
/**
|
|
|
|
* Return ApiClient object
|
|
|
|
*
|
|
|
|
* @param string $url (default: null)
|
|
|
|
* @param string $apiKey (default: null)
|
2014-11-27 11:23:44 +03:00
|
|
|
* @param string $site (default: null)
|
2014-11-06 02:44:52 +03:00
|
|
|
* @return ApiClient
|
|
|
|
*/
|
2014-11-27 11:23:44 +03:00
|
|
|
public static function getApiClient($url = null, $apiKey = null, $site = null)
|
2014-11-06 02:44:52 +03:00
|
|
|
{
|
2014-11-27 11:23:44 +03:00
|
|
|
return new ApiClient(
|
|
|
|
$url ?: $_SERVER['CRM_URL'],
|
|
|
|
$apiKey ?: $_SERVER['CRM_API_KEY'],
|
|
|
|
$site ?: (isset($_SERVER['CRM_SITE']) ? $_SERVER['CRM_SITE'] : null)
|
|
|
|
);
|
2014-11-06 02:44:52 +03:00
|
|
|
}
|
2016-11-28 14:38:03 +03:00
|
|
|
|
2015-05-04 18:47:14 +03:00
|
|
|
/**
|
|
|
|
* Return Client object
|
|
|
|
*
|
2016-03-12 01:54:33 +03:00
|
|
|
* @param string $url (default: null)
|
|
|
|
* @param array $defaultParameters (default: array())
|
|
|
|
*
|
2015-05-04 18:47:14 +03:00
|
|
|
* @return Client
|
|
|
|
*/
|
|
|
|
public static function getClient($url = null, $defaultParameters = array())
|
|
|
|
{
|
|
|
|
return new Client(
|
|
|
|
$url ?: $_SERVER['CRM_URL'] . '/api/' . ApiClient::VERSION,
|
2016-03-12 01:54:33 +03:00
|
|
|
array(
|
|
|
|
'apiKey' => array_key_exists('apiKey', $defaultParameters)
|
|
|
|
? $defaultParameters['apiKey']
|
|
|
|
: $_SERVER['CRM_API_KEY']
|
|
|
|
)
|
2015-05-04 18:47:14 +03:00
|
|
|
);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|