2014-11-06 02:44:52 +03:00
|
|
|
<?php
|
|
|
|
|
|
|
|
namespace RetailCrm\Tests\Http;
|
|
|
|
|
|
|
|
use RetailCrm\Test\TestCase;
|
|
|
|
use RetailCrm\ApiClient;
|
|
|
|
use RetailCrm\Http\Client;
|
|
|
|
|
|
|
|
class ClientTest extends TestCase
|
|
|
|
{
|
|
|
|
/**
|
|
|
|
* @group unit
|
|
|
|
*/
|
|
|
|
public function testConstruct()
|
|
|
|
{
|
|
|
|
$client = new Client('https://asdf.df', array());
|
|
|
|
|
|
|
|
$this->assertInstanceOf('RetailCrm\Http\Client', $client);
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @group unit
|
|
|
|
* @expectedException \InvalidArgumentException
|
|
|
|
*/
|
|
|
|
public function testHttpRequiring()
|
|
|
|
{
|
2015-05-04 18:47:14 +03:00
|
|
|
$client = new Client('http://demo.retailcrm.ru/api/' . ApiClient::VERSION, array('apiKey' => '123'));
|
2014-11-06 02:44:52 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @group unit
|
|
|
|
* @expectedException \InvalidArgumentException
|
|
|
|
*/
|
|
|
|
public function testMakeRequestWrongMethod()
|
|
|
|
{
|
2015-05-04 18:47:14 +03:00
|
|
|
$client = static::getClient();
|
2014-11-06 02:44:52 +03:00
|
|
|
$client->makeRequest('/a', 'adsf');
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @group integration
|
2015-04-30 17:35:57 +03:00
|
|
|
* @expectedException \RetailCrm\Exception\CurlException
|
2014-11-06 02:44:52 +03:00
|
|
|
*/
|
|
|
|
public function testMakeRequestWrongUrl()
|
|
|
|
{
|
|
|
|
$client = new Client('https://asdf.df', array());
|
|
|
|
$client->makeRequest('/a', Client::METHOD_GET, array(), 1);
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @group integration
|
|
|
|
*/
|
|
|
|
public function testMakeRequestSuccess()
|
|
|
|
{
|
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
|
|
|
|
|
|
|
$this->assertInstanceOf('RetailCrm\Response\ApiResponse', $response);
|
2015-05-04 18:47:14 +03:00
|
|
|
$this->assertEquals(200, $response->getStatusCode());
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @group integration
|
|
|
|
*/
|
2015-06-15 17:50:31 +03:00
|
|
|
public function testMakeRequestRepeatOnTimeout()
|
2015-05-04 18:47:14 +03:00
|
|
|
{
|
|
|
|
$client = static::getClient();
|
2015-06-15 17:50:31 +03:00
|
|
|
$response = $client->makeRequest('/orders', Client::METHOD_GET, array(), 1, false, true);
|
|
|
|
$this->assertGreaterThanOrEqual(1, $client->retry);
|
2014-11-06 02:44:52 +03:00
|
|
|
}
|
|
|
|
}
|