1
0
mirror of synced 2024-11-23 13:16:02 +03:00
aliexpress-top-client/tests/RetailCrm/Tests/TopClient/ClientTest.php

63 lines
1.9 KiB
PHP
Raw Normal View History

2020-09-25 18:06:41 +03:00
<?php
/**
* PHP version 7.3
2020-09-25 18:06:41 +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
*/
namespace RetailCrm\Tests\TopClient;
2020-09-25 18:06:41 +03:00
use Psr\Http\Message\RequestInterface;
use RetailCrm\Builder\ClientBuilder;
use RetailCrm\Component\AppData;
2020-09-28 16:08:55 +03:00
use RetailCrm\Component\Authenticator\TokenAuthenticator;
use RetailCrm\Model\Request\HttpDnsGetRequest;
use RetailCrm\Model\Response\BaseResponse;
use RetailCrm\Model\Response\Body\ErrorResponseBody;
use RetailCrm\Test\ClosureRequestMatcher;
use RetailCrm\Test\TestCase;
2020-09-25 18:06:41 +03:00
/**
* Class ClientTest
2020-09-25 18:06:41 +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
*/
class ClientTest extends TestCase
2020-09-25 18:06:41 +03:00
{
public function testClientRequestException()
2020-09-25 18:06:41 +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()
->setContainer($this->getContainer($mockClient))
->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
$this->expectExceptionMessage($errorBody->msg);
$client->sendRequest(new HttpDnsGetRequest());
2020-09-25 18:06:41 +03:00
}
}