1
0
mirror of synced 2024-11-26 23:36:06 +03:00
api-client-php/tests/RetailCrm/Tests/Http/ClientTest.php

99 lines
2.6 KiB
PHP
Raw Normal View History

<?php
2016-07-22 01:01:47 +03:00
/**
* PHP version 5.4
2016-07-22 01:01:47 +03:00
*
* API client test 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
2016-07-22 01:01:47 +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
* @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
2016-07-22 01:01:47 +03:00
*/
class ClientTest extends TestCase
{
/**
* @group client
*/
public function testConstruct()
{
$client = new Client('https://asdf.df', []);
static::assertInstanceOf('RetailCrm\Http\Client', $client);
}
/**
* @group client
* @expectedException \InvalidArgumentException
*/
public function testHttpRequiring()
{
$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;
}
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);
}
/**
* @group client
* @expectedException \InvalidArgumentException
*/
public function testRequestWrongMethod()
{
$client = static::getClient();
$client->makeRequest('/a', 'adsf');
}
/**
* @group client
* @expectedException \RetailCrm\Exception\CurlException
*/
public function testRequestWrongUrl()
{
$client = new Client('https://asdf.df', []);
$client->makeRequest('/a', Client::METHOD_GET, []);
}
/**
* @group client
*/
public function testRequestSuccess()
{
$client = static::getClient();
2014-11-06 03:18:39 +03:00
$response = $client->makeRequest('/orders', Client::METHOD_GET);
static::assertInstanceOf('RetailCrm\Response\ApiResponse', $response);
static::assertEquals(200, $response->getStatusCode());
}
}