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-10-01 12:43:07 +03:00
|
|
|
use RetailCrm\Model\Request\Taobao\HttpDnsGetRequest;
|
2020-09-30 13:18:35 +03:00
|
|
|
use RetailCrm\Model\Response\BaseResponse;
|
2020-10-01 12:43:07 +03:00
|
|
|
use RetailCrm\Model\Response\ErrorResponseBody;
|
2020-09-30 13:18:35 +03:00
|
|
|
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-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
|
|
|
}
|
2020-10-01 10:34:42 +03:00
|
|
|
|
|
|
|
public function testClientRequestXmlUnsupported()
|
|
|
|
{
|
|
|
|
$client = ClientBuilder::create()
|
|
|
|
->setContainer($this->getContainer(self::getMockClient()))
|
|
|
|
->setAppData(new AppData(AppData::OVERSEAS_ENDPOINT, 'appKey', 'appSecret'))
|
|
|
|
->build();
|
|
|
|
|
|
|
|
$request = new HttpDnsGetRequest();
|
|
|
|
$request->format = 'xml';
|
|
|
|
|
|
|
|
$this->expectExceptionMessage('Client only supports JSON mode, got `xml` mode');
|
|
|
|
$client->sendRequest($request);
|
|
|
|
}
|
2020-09-25 18:06:41 +03:00
|
|
|
}
|