2020-09-25 18:06:41 +03:00
|
|
|
<?php
|
|
|
|
|
|
|
|
/**
|
2020-09-29 15:18:03 +03:00
|
|
|
* PHP version 7.3
|
2020-09-25 18:06:41 +03:00
|
|
|
*
|
2020-09-29 15:18:03 +03:00
|
|
|
* @category ClientTest
|
|
|
|
* @package RetailCrm\Tests\TopClient
|
2020-09-25 18:06:41 +03:00
|
|
|
* @author RetailCRM <integration@retailcrm.ru>
|
|
|
|
* @license MIT
|
|
|
|
* @link http://retailcrm.ru
|
|
|
|
* @see http://help.retailcrm.ru
|
|
|
|
*/
|
2020-09-29 15:18:03 +03:00
|
|
|
namespace RetailCrm\Tests\TopClient;
|
2020-09-25 18:06:41 +03:00
|
|
|
|
2020-09-30 13:18:35 +03:00
|
|
|
use Psr\Http\Message\RequestInterface;
|
2020-09-29 15:18:03 +03:00
|
|
|
use RetailCrm\Builder\ClientBuilder;
|
2020-09-28 17:18:21 +03:00
|
|
|
use RetailCrm\Component\AppData;
|
2020-09-28 16:08:55 +03:00
|
|
|
use RetailCrm\Component\Authenticator\TokenAuthenticator;
|
2020-09-29 15:18:03 +03:00
|
|
|
use RetailCrm\Model\Request\HttpDnsGetRequest;
|
2020-09-30 13:18:35 +03:00
|
|
|
use RetailCrm\Model\Response\BaseResponse;
|
|
|
|
use RetailCrm\Model\Response\Body\ErrorResponseBody;
|
|
|
|
use RetailCrm\Test\ClosureRequestMatcher;
|
2020-09-28 17:18:21 +03:00
|
|
|
use RetailCrm\Test\TestCase;
|
2020-09-25 18:06:41 +03:00
|
|
|
|
|
|
|
/**
|
2020-09-29 15:18:03 +03:00
|
|
|
* Class ClientTest
|
2020-09-25 18:06:41 +03:00
|
|
|
*
|
2020-09-29 15:18:03 +03:00
|
|
|
* @category ClientTest
|
|
|
|
* @package RetailCrm\Tests\TopClient
|
2020-09-25 18:06:41 +03:00
|
|
|
* @author RetailDriver LLC <integration@retailcrm.ru>
|
|
|
|
* @license MIT
|
|
|
|
* @link http://retailcrm.ru
|
|
|
|
* @see https://help.retailcrm.ru
|
|
|
|
*/
|
2020-09-29 15:18:03 +03:00
|
|
|
class ClientTest extends TestCase
|
2020-09-25 18:06:41 +03:00
|
|
|
{
|
2020-09-30 13:18:35 +03:00
|
|
|
public function testClientRequestException()
|
2020-09-25 18:06:41 +03:00
|
|
|
{
|
2020-09-30 13:18:35 +03:00
|
|
|
$errorBody = new ErrorResponseBody();
|
|
|
|
$errorBody->code = 999;
|
|
|
|
$errorBody->msg = 'Mocked error';
|
|
|
|
$errorBody->subCode = 'subcode';
|
|
|
|
$errorBody->requestId = '1';
|
|
|
|
$errorResponse = new BaseResponse();
|
|
|
|
$errorResponse->errorResponse = $errorBody;
|
|
|
|
|
|
|
|
$mockClient = self::getMockClient();
|
|
|
|
$mockClient->on(new ClosureRequestMatcher(function (RequestInterface $request) {
|
|
|
|
return true;
|
|
|
|
}), $this->responseJson(400, $errorResponse));
|
2020-09-29 15:19:44 +03:00
|
|
|
|
2020-09-29 14:18:53 +03:00
|
|
|
$client = ClientBuilder::create()
|
2020-09-30 13:18:35 +03:00
|
|
|
->setContainer($this->getContainer($mockClient))
|
2020-09-29 15:18:03 +03:00
|
|
|
->setAppData(new AppData(AppData::OVERSEAS_ENDPOINT, 'appKey', 'appSecret'))
|
2020-09-28 16:08:55 +03:00
|
|
|
->setAuthenticator(new TokenAuthenticator('appKey', 'token'))
|
2020-09-29 14:18:53 +03:00
|
|
|
->build();
|
2020-09-25 18:06:41 +03:00
|
|
|
|
2020-09-30 13:18:35 +03:00
|
|
|
$this->expectExceptionMessage($errorBody->msg);
|
|
|
|
|
2020-09-29 15:18:03 +03:00
|
|
|
$client->sendRequest(new HttpDnsGetRequest());
|
2020-09-25 18:06:41 +03:00
|
|
|
}
|
|
|
|
}
|