2014-11-06 02:44:52 +03:00
|
|
|
<?php
|
|
|
|
|
2016-07-22 01:01:47 +03:00
|
|
|
/**
|
2017-06-22 00:55:08 +03:00
|
|
|
* PHP version 5.4
|
2016-07-22 01:01:47 +03:00
|
|
|
*
|
|
|
|
* API client test class
|
|
|
|
*
|
|
|
|
* @category RetailCrm
|
|
|
|
* @package RetailCrm
|
|
|
|
*/
|
|
|
|
|
2014-11-06 02:44:52 +03:00
|
|
|
namespace RetailCrm\Tests\Http;
|
|
|
|
|
|
|
|
use RetailCrm\Test\TestCase;
|
|
|
|
use RetailCrm\Http\Client;
|
|
|
|
|
2016-07-22 01:01:47 +03:00
|
|
|
/**
|
|
|
|
* Class ClientTest
|
|
|
|
*
|
|
|
|
* @category RetailCrm
|
|
|
|
* @package RetailCrm
|
|
|
|
*/
|
2014-11-06 02:44:52 +03:00
|
|
|
class ClientTest extends TestCase
|
|
|
|
{
|
|
|
|
/**
|
2017-06-22 00:55:08 +03:00
|
|
|
* @group client
|
2014-11-06 02:44:52 +03:00
|
|
|
*/
|
|
|
|
public function testConstruct()
|
|
|
|
{
|
2017-06-22 00:55:08 +03:00
|
|
|
$client = new Client('https://asdf.df', []);
|
2014-11-06 02:44:52 +03:00
|
|
|
|
2017-06-22 00:55:08 +03:00
|
|
|
static::assertInstanceOf('RetailCrm\Http\Client', $client);
|
2014-11-06 02:44:52 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
2017-06-22 00:55:08 +03:00
|
|
|
* @group client
|
2014-11-06 02:44:52 +03:00
|
|
|
* @expectedException \InvalidArgumentException
|
|
|
|
*/
|
|
|
|
public function testHttpRequiring()
|
|
|
|
{
|
2018-02-20 17:50:45 +03:00
|
|
|
$configVersion = getenv('RETAILCRM_VERSION') ?: $_SERVER['RETAILCRM_VERSION'];
|
|
|
|
$client = new Client('http://demo.retailcrm.ru/api/' . $configVersion, ['apiKey' => '123']);
|
|
|
|
|
2016-07-22 01:01:47 +03:00
|
|
|
return $client;
|
2014-11-06 02:44:52 +03:00
|
|
|
}
|
|
|
|
|
2019-08-30 14:10:52 +03:00
|
|
|
/**
|
|
|
|
* @group client
|
|
|
|
*/
|
|
|
|
public function testHttpDebug()
|
|
|
|
{
|
|
|
|
$client_v3 = new Client('http://demo.retailcrm.ru/api/v3', ['apiKey' => '123'], true);
|
|
|
|
$client_v4 = new Client('http://demo.retailcrm.ru/api/v4', ['apiKey' => '123'], true);
|
|
|
|
$client_v5 = new Client('http://demo.retailcrm.ru/api/v5', ['apiKey' => '123'], true);
|
|
|
|
|
|
|
|
static::assertInstanceOf('RetailCrm\Http\Client', $client_v3);
|
|
|
|
static::assertInstanceOf('RetailCrm\Http\Client', $client_v4);
|
|
|
|
static::assertInstanceOf('RetailCrm\Http\Client', $client_v5);
|
|
|
|
}
|
|
|
|
|
2014-11-06 02:44:52 +03:00
|
|
|
/**
|
2017-06-22 00:55:08 +03:00
|
|
|
* @group client
|
2014-11-06 02:44:52 +03:00
|
|
|
* @expectedException \InvalidArgumentException
|
|
|
|
*/
|
2017-06-22 00:55:08 +03:00
|
|
|
public function testRequestWrongMethod()
|
2014-11-06 02:44:52 +03:00
|
|
|
{
|
2015-05-04 18:47:14 +03:00
|
|
|
$client = static::getClient();
|
2014-11-06 02:44:52 +03:00
|
|
|
$client->makeRequest('/a', 'adsf');
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
2017-06-22 00:55:08 +03:00
|
|
|
* @group client
|
2015-04-30 17:35:57 +03:00
|
|
|
* @expectedException \RetailCrm\Exception\CurlException
|
2014-11-06 02:44:52 +03:00
|
|
|
*/
|
2017-06-22 00:55:08 +03:00
|
|
|
public function testRequestWrongUrl()
|
2014-11-06 02:44:52 +03:00
|
|
|
{
|
2017-06-22 00:55:08 +03:00
|
|
|
$client = new Client('https://asdf.df', []);
|
|
|
|
$client->makeRequest('/a', Client::METHOD_GET, []);
|
2014-11-06 02:44:52 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
2017-06-22 00:55:08 +03:00
|
|
|
* @group client
|
2014-11-06 02:44:52 +03:00
|
|
|
*/
|
2017-06-22 00:55:08 +03:00
|
|
|
public function testRequestSuccess()
|
2014-11-06 02:44:52 +03:00
|
|
|
{
|
2015-05-04 18:47:14 +03:00
|
|
|
$client = static::getClient();
|
2014-11-06 03:18:39 +03:00
|
|
|
$response = $client->makeRequest('/orders', Client::METHOD_GET);
|
2014-11-06 02:44:52 +03:00
|
|
|
|
2017-06-22 00:55:08 +03:00
|
|
|
static::assertInstanceOf('RetailCrm\Response\ApiResponse', $response);
|
2020-02-11 10:57:17 +03:00
|
|
|
static::assertNotEmpty($response->getResponseBody());
|
|
|
|
static::assertNotEmpty($response->getResponse());
|
|
|
|
static::assertEquals(200, $response->getStatusCode());
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @group client
|
|
|
|
*/
|
|
|
|
public function testRequestSuccessNoDeserialization()
|
|
|
|
{
|
|
|
|
$client = static::getClient();
|
|
|
|
$response = $client->makeRawRequest('/orders', Client::METHOD_GET);
|
|
|
|
|
|
|
|
static::assertInstanceOf('RetailCrm\Response\ApiResponse', $response);
|
|
|
|
static::assertNotEmpty($response->getResponseBody());
|
|
|
|
static::assertEmpty($response->getResponse());
|
2017-06-22 00:55:08 +03:00
|
|
|
static::assertEquals(200, $response->getStatusCode());
|
2015-05-04 18:47:14 +03:00
|
|
|
}
|
2014-11-06 02:44:52 +03:00
|
|
|
}
|