1
0
mirror of synced 2024-11-21 20:36:03 +03:00

structure change for models & add another request and response models & matcher for tests & more tests

This commit is contained in:
Pavel 2020-10-01 14:59:40 +03:00
parent c378ad5385
commit 18f8675005
17 changed files with 731 additions and 104 deletions

View File

@ -0,0 +1,67 @@
<?php
/**
* PHP version 7.4
*
* @category PostproductRedefiningCategoryForecastResponse
* @package RetailCrm\Model\Request\AliExpress
* @author RetailCRM <integration@retailcrm.ru>
* @license http://retailcrm.ru Proprietary
* @link http://retailcrm.ru
* @see http://help.retailcrm.ru
*/
namespace RetailCrm\Model\Request\AliExpress;
use JMS\Serializer\Annotation as JMS;
use RetailCrm\Model\Request\BaseRequest;
use RetailCrm\Model\Response\AliExpress\PostproductRedefiningCategoryForecastResponse;
use Symfony\Component\Validator\Constraints as Assert;
/**
* Class PostproductRedefiningCategoryForecastResponse
*
* @category PostproductRedefiningCategoryForecastResponse
* @package RetailCrm\Model\Request\AliExpress
* @author RetailDriver LLC <integration@retailcrm.ru>
* @license https://retailcrm.ru Proprietary
* @link http://retailcrm.ru
* @see https://help.retailcrm.ru
*/
class PostproductRedefiningCategoryForecast extends BaseRequest
{
/**
* @var string $subject
*
* @JMS\Type("string")
* @JMS\SerializedName("subject")
* @Assert\LessThanOrEqual(512)
*/
public $subject;
/**
* @var string $locale
*
* @JMS\Type("string")
* @JMS\SerializedName("locale")
*
* phpcs:disable Generic.Files.LineLength
* @Assert\Choice({"en", "ru", "pt", "id", "es", "fr", "it", "de", "nl", "tr", "he", "ja", "ar", "th", "vi", "ko", "pl"})
*/
public $locale;
/**
* @inheritDoc
*/
public function getMethod(): string
{
return 'aliexpress.postproduct.redefining.categoryforecast';
}
/**
* @inheritDoc
*/
public function getExpectedResponse(): string
{
return PostproductRedefiningCategoryForecastResponse::class;
}
}

View File

@ -2,32 +2,32 @@
/**
* PHP version 7.4
*
* @category SellerCategoryTreeQuery
* @package RetailCrm\Model\Request\AliExpressSolution
* @category SolutionSellerCategoryTreeQuery
* @package RetailCrm\Model\Request\AliExpress
* @author RetailCRM <integration@retailcrm.ru>
* @license http://retailcrm.ru Proprietary
* @link http://retailcrm.ru
* @see http://help.retailcrm.ru
*/
namespace RetailCrm\Model\Request\AliExpressSolution;
namespace RetailCrm\Model\Request\AliExpress;
use RetailCrm\Model\Request\BaseRequest;
use JMS\Serializer\Annotation as JMS;
use RetailCrm\Model\Response\AliExpressSolution\SellerCategoryTreeQueryResponse;
use RetailCrm\Model\Response\AliExpress\SolutionSellerCategoryTreeQueryResponse;
use Symfony\Component\Validator\Constraints as Assert;
/**
* Class SellerCategoryTreeQuery
* Class SolutionSellerCategoryTreeQuery
*
* @category SellerCategoryTreeQuery
* @package RetailCrm\Model\Request\AliExpressSolution
* @category SolutionSellerCategoryTreeQuery
* @package RetailCrm\Model\Request\AliExpress
* @author RetailDriver LLC <integration@retailcrm.ru>
* @license https://retailcrm.ru Proprietary
* @link http://retailcrm.ru
* @see https://help.retailcrm.ru
*/
class SellerCategoryTreeQuery extends BaseRequest
class SolutionSellerCategoryTreeQuery extends BaseRequest
{
/**
* @var int $categoryId
@ -61,6 +61,6 @@ class SellerCategoryTreeQuery extends BaseRequest
*/
public function getExpectedResponse(): string
{
return SellerCategoryTreeQueryResponse::class;
return SolutionSellerCategoryTreeQueryResponse::class;
}
}

View File

@ -0,0 +1,36 @@
<?php
/**
* PHP version 7.4
*
* @category AbstractResponseData
* @package RetailCrm\Model\Response
* @author RetailCRM <integration@retailcrm.ru>
* @license http://retailcrm.ru Proprietary
* @link http://retailcrm.ru
* @see http://help.retailcrm.ru
*/
namespace RetailCrm\Model\Response;
use JMS\Serializer\Annotation as JMS;
/**
* Class AbstractResponseData
*
* @category AbstractResponseData
* @package RetailCrm\Model\Response
* @author RetailDriver LLC <integration@retailcrm.ru>
* @license https://retailcrm.ru Proprietary
* @link http://retailcrm.ru
* @see https://help.retailcrm.ru
*/
abstract class AbstractResponseData
{
/**
* @var string $requestId
*
* @JMS\Type("string")
* @JMS\SerializedName("request_id")
*/
public $requestId;
}

View File

@ -0,0 +1,37 @@
<?php
/**
* PHP version 7.4
*
* @category PostproductRedefiningCategoryForecastResponseData
* @package RetailCrm\Model\Response\AliExpress\Data
* @author RetailCRM <integration@retailcrm.ru>
* @license http://retailcrm.ru Proprietary
* @link http://retailcrm.ru
* @see http://help.retailcrm.ru
*/
namespace RetailCrm\Model\Response\AliExpress\Data;
use JMS\Serializer\Annotation as JMS;
use RetailCrm\Model\Response\AbstractResponseData;
/**
* Class PostproductRedefiningCategoryForecastResponseData
*
* @category PostproductRedefiningCategoryForecastResponseData
* @package RetailCrm\Model\Response\AliExpress\Data
* @author RetailDriver LLC <integration@retailcrm.ru>
* @license https://retailcrm.ru Proprietary
* @link http://retailcrm.ru
* @see https://help.retailcrm.ru
*/
class PostproductRedefiningCategoryForecastResponseData extends AbstractResponseData
{
/**
* @var \RetailCrm\Model\Response\AliExpress\Result\AeopCategoryForecastResultDto $result
*
* @JMS\Type("RetailCrm\Model\Response\AliExpress\Result\AeopCategoryForecastResultDto")
* @JMS\SerializedName("result")
*/
public $result;
}

View File

@ -2,34 +2,35 @@
/**
* PHP version 7.4
*
* @category SellerCategoryTreeQueryResponseData
* @package RetailCrm\Model\Response\AliExpressSolution\Data
* @category SolutionSellerCategoryTreeQueryResponseData
* @package RetailCrm\Model\Response\AliExpress\Data
* @author RetailCRM <integration@retailcrm.ru>
* @license http://retailcrm.ru Proprietary
* @link http://retailcrm.ru
* @see http://help.retailcrm.ru
*/
namespace RetailCrm\Model\Response\AliExpressSolution\Data;
namespace RetailCrm\Model\Response\AliExpress\Data;
use JMS\Serializer\Annotation as JMS;
use RetailCrm\Model\Response\AbstractResponseData;
/**
* Class SellerCategoryTreeQueryResponseData
* Class SolutionSellerCategoryTreeQueryResponseData
*
* @category SellerCategoryTreeQueryResponseData
* @category SolutionSellerCategoryTreeQueryResponseData
* @package RetailCrm\Model\Response\AliExpressSolution\Data
* @author RetailDriver LLC <integration@retailcrm.ru>
* @license https://retailcrm.ru Proprietary
* @link http://retailcrm.ru
* @see https://help.retailcrm.ru
*/
class SellerCategoryTreeQueryResponseData
class SolutionSellerCategoryTreeQueryResponseData extends AbstractResponseData
{
/**
* @var SellerCategoryTreeQueryResponseDataChildrenCategoryList
* @var SolutionSellerCategoryTreeQueryResponseDataChildrenCategoryList
*
* @JMS\Type("RetailCrm\Model\Response\AliExpressSolution\Data\SellerCategoryTreeQueryResponseDataChildrenCategoryList")
* @JMS\Type("RetailCrm\Model\Response\AliExpress\Data\SolutionSellerCategoryTreeQueryResponseDataChildrenCategoryList")
* @JMS\SerializedName("children_category_list")
*/
public $childrenCategoryList;

View File

@ -2,30 +2,30 @@
/**
* PHP version 7.4
*
* @category SellerCategoryTreeQueryResponseDataChildrenCategoryList
* @package RetailCrm\Model\Response\AliExpressSolution\Data
* @category SolutionSellerCategoryTreeQueryResponseDataChildrenCategoryList
* @package RetailCrm\Model\Response\AliExpress\Data
* @author RetailCRM <integration@retailcrm.ru>
* @license http://retailcrm.ru Proprietary
* @link http://retailcrm.ru
* @see http://help.retailcrm.ru
*/
namespace RetailCrm\Model\Response\AliExpressSolution\Data;
namespace RetailCrm\Model\Response\AliExpress\Data;
use RetailCrm\Model\Entity\CategoryInfo;
use JMS\Serializer\Annotation as JMS;
/**
* Class SellerCategoryTreeQueryResponseDataChildrenCategoryList
* Class SolutionSellerCategoryTreeQueryResponseDataChildrenCategoryList
*
* @category SellerCategoryTreeQueryResponseDataChildrenCategoryList
* @package RetailCrm\Model\Response\AliExpressSolution\Data
* @category SolutionSellerCategoryTreeQueryResponseDataChildrenCategoryList
* @package RetailCrm\Model\Response\AliExpress\Data
* @author RetailDriver LLC <integration@retailcrm.ru>
* @license https://retailcrm.ru Proprietary
* @link http://retailcrm.ru
* @see https://help.retailcrm.ru
*/
class SellerCategoryTreeQueryResponseDataChildrenCategoryList
class SolutionSellerCategoryTreeQueryResponseDataChildrenCategoryList
{
/**
* @var CategoryInfo[] $categoryInfo

View File

@ -0,0 +1,39 @@
<?php
/**
* PHP version 7.4
*
* @category PostproductRedefiningCategoryForecastResponse
* @package RetailCrm\Model\Response\AliExpress
* @author RetailCRM <integration@retailcrm.ru>
* @license http://retailcrm.ru Proprietary
* @link http://retailcrm.ru
* @see http://help.retailcrm.ru
*/
namespace RetailCrm\Model\Response\AliExpress;
use RetailCrm\Model\Response\AliExpress\Data\PostproductRedefiningCategoryForecastResponseData;
use RetailCrm\Model\Response\BaseResponse;
use JMS\Serializer\Annotation as JMS;
/**
* Class PostproductRedefiningCategoryForecastResponse
*
* @category PostproductRedefiningCategoryForecastResponse
* @package RetailCrm\Model\Response\AliExpress
* @author RetailDriver LLC <integration@retailcrm.ru>
* @license https://retailcrm.ru Proprietary
* @link http://retailcrm.ru
* @see https://help.retailcrm.ru
*/
class PostproductRedefiningCategoryForecastResponse extends BaseResponse
{
/**
* @var PostproductRedefiningCategoryForecastResponseData $responseData
*
* @JMS\Type("RetailCrm\Model\Response\AliExpress\Data\PostproductRedefiningCategoryForecastResponseData")
* @JMS\SerializedName("aliexpress_postproduct_redefining_categoryforecast_response")
*/
public $responseData;
}

View File

@ -0,0 +1,68 @@
<?php
/**
* PHP version 7.4
*
* @category AeopCategoryForecastResultDto
* @package RetailCrm\Model\Response\AliExpress\Result
* @author RetailCRM <integration@retailcrm.ru>
* @license http://retailcrm.ru Proprietary
* @link http://retailcrm.ru
* @see http://help.retailcrm.ru
*/
namespace RetailCrm\Model\Response\AliExpress\Result;
use JMS\Serializer\Annotation as JMS;
/**
* Class AeopCategoryForecastResultDto
*
* @category AeopCategoryForecastResultDto
* @package RetailCrm\Model\Response\AliExpress\Result
* @author RetailDriver LLC <integration@retailcrm.ru>
* @license https://retailcrm.ru Proprietary
* @link http://retailcrm.ru
* @see https://help.retailcrm.ru
*/
class AeopCategoryForecastResultDto
{
/**
* @var string $errorMessage
*
* @JMS\Type("string")
* @JMS\SerializedName("error_message")
*/
public $errorMessage;
/**
* @var \RetailCrm\Model\Response\AliExpress\Result\Entity\CategorySuitabilityList $categorySuitabilityList
*
* @JMS\Type("RetailCrm\Model\Response\AliExpress\Result\Entity\CategorySuitabilityList")
* @JMS\SerializedName("category_suitability_list")
*/
public $categorySuitabilityList;
/**
* @var string $timeStamp
*
* @JMS\Type("string")
* @JMS\SerializedName("time_stamp")
*/
public $timeStamp;
/**
* @var string $errorCode
*
* @JMS\Type("string")
* @JMS\SerializedName("error_code")
*/
public $errorCode;
/**
* @var bool $success
*
* @JMS\Type("bool")
* @JMS\SerializedName("success")
*/
public $success;
}

View File

@ -0,0 +1,36 @@
<?php
/**
* PHP version 7.4
*
* @category CategorySuitabilityList
* @package RetailCrm\Model\Response\AliExpress\Result\Entity
* @author RetailCRM <integration@retailcrm.ru>
* @license http://retailcrm.ru Proprietary
* @link http://retailcrm.ru
* @see http://help.retailcrm.ru
*/
namespace RetailCrm\Model\Response\AliExpress\Result\Entity;
use JMS\Serializer\Annotation as JMS;
/**
* Class CategorySuitabilityList
*
* @category CategorySuitabilityList
* @package RetailCrm\Model\Response\AliExpress\Result\Entity
* @author RetailDriver LLC <integration@retailcrm.ru>
* @license https://retailcrm.ru Proprietary
* @link http://retailcrm.ru
* @see https://help.retailcrm.ru
*/
class CategorySuitabilityList
{
/**
* @var string[] $json
*
* @JMS\Type("array<string>")
* @JMS\SerializedName("json")
*/
public $json;
}

View File

@ -2,7 +2,7 @@
/**
* PHP version 7.4
*
* @category SellerCategoryTreeQueryResponse
* @category SolutionSellerCategoryTreeQueryResponse
* @package RetailCrm\Model\Response\AliExpressSolution
* @author RetailCRM <integration@retailcrm.ru>
* @license http://retailcrm.ru Proprietary
@ -10,28 +10,28 @@
* @see http://help.retailcrm.ru
*/
namespace RetailCrm\Model\Response\AliExpressSolution;
namespace RetailCrm\Model\Response\AliExpress;
use RetailCrm\Model\Response\BaseResponse;
use JMS\Serializer\Annotation as JMS;
/**
* Class SellerCategoryTreeQueryResponse
* Class SolutionSellerCategoryTreeQueryResponse
*
* @category SellerCategoryTreeQueryResponse
* @category SolutionSellerCategoryTreeQueryResponse
* @package RetailCrm\Model\Response\AliExpressSolution
* @author RetailDriver LLC <integration@retailcrm.ru>
* @license https://retailcrm.ru Proprietary
* @link http://retailcrm.ru
* @see https://help.retailcrm.ru
*/
class SellerCategoryTreeQueryResponse extends BaseResponse
class SolutionSellerCategoryTreeQueryResponse extends BaseResponse
{
/**
* @var \RetailCrm\Model\Response\AliExpressSolution\Data\SellerCategoryTreeQueryResponseData $responseData
* @var \RetailCrm\Model\Response\AliExpress\Data\SolutionSellerCategoryTreeQueryResponseData $responseData
*
* @JMS\Type("RetailCrm\Model\Response\AliExpressSolution\Data\SellerCategoryTreeQueryResponseData")
* @JMS\Type("RetailCrm\Model\Response\AliExpress\Data\SolutionSellerCategoryTreeQueryResponseData")
* @JMS\SerializedName("aliexpress_solution_seller_category_tree_query_response")
*/
public $responseData;

View File

@ -24,7 +24,7 @@ use JMS\Serializer\Annotation as JMS;
* @link http://retailcrm.ru
* @see https://help.retailcrm.ru
*/
class BaseResponse implements TopResponseInterface
abstract class BaseResponse implements TopResponseInterface
{
/**
* @var \RetailCrm\Model\Response\ErrorResponseBody

View File

@ -13,6 +13,7 @@
namespace RetailCrm\Model\Response\Taobao\Data;
use JMS\Serializer\Annotation as JMS;
use RetailCrm\Model\Response\AbstractResponseData;
use RetailCrm\Model\Response\Taobao\Result\HttpDnsGetResponseResult;
/**
@ -25,7 +26,7 @@ use RetailCrm\Model\Response\Taobao\Result\HttpDnsGetResponseResult;
* @link http://retailcrm.ru
* @see https://help.retailcrm.ru
*/
class HttpDnsGetResponseData
class HttpDnsGetResponseData extends AbstractResponseData
{
/**
* @var HttpDnsGetResponseResult $result

View File

@ -1,58 +0,0 @@
<?php
/**
* PHP version 7.3
*
* @category RequestMatcher
* @package RetailCrm\Test
* @author RetailCRM <integration@retailcrm.ru>
* @license MIT
* @link http://retailcrm.ru
* @see http://help.retailcrm.ru
*/
namespace RetailCrm\Test;
use Http\Message\RequestMatcher;
use InvalidArgumentException;
use Psr\Http\Message\RequestInterface;
/**
* Class ClosureRequestMatcher
*
* @category ClosureRequestMatcher
* @package RetailCrm\Test
* @author RetailDriver LLC <integration@retailcrm.ru>
* @license MIT
* @link http://retailcrm.ru
* @see https://help.retailcrm.ru
*/
class ClosureRequestMatcher implements RequestMatcher
{
/**
* @var callable $matcher
*/
private $matcher;
/**
* RequestMatcher constructor.
*
* @param callable $matcher
*/
public function __construct(callable $matcher)
{
if (!is_callable($matcher)) {
throw new InvalidArgumentException('Matcher should be callable');
}
$this->matcher = $matcher;
}
/**
* @inheritDoc
*/
public function matches(RequestInterface $request): bool
{
$matcher = $this->matcher;
return $matcher($request);
}
}

View File

@ -0,0 +1,239 @@
<?php
/**
* PHP version 7.4
*
* @category RequestMatcher
* @package RetailCrm\Test
* @author RetailCRM <integration@retailcrm.ru>
* @license http://retailcrm.ru Proprietary
* @link http://retailcrm.ru
* @see http://help.retailcrm.ru
*/
namespace RetailCrm\Test;
use Http\Message\RequestMatcher as RequestMatcherInterface;
use Psr\Http\Message\RequestInterface;
/**
* Class RequestMatcher
*
* @category RequestMatcher
* @package RetailCrm\Test
* @author RetailDriver LLC <integration@retailcrm.ru>
* @license https://retailcrm.ru Proprietary
* @link http://retailcrm.ru
* @see https://help.retailcrm.ru
*/
class RequestMatcher implements RequestMatcherInterface
{
/**
* @var string
*/
private $path;
/**
* @var string
*/
private $host;
/**
* @var string
*/
private $method;
/**
* @var string
*/
private $scheme;
/**
* @var array
*/
private $headers = [];
/**
* @var array
*/
private $optionalHeaders = [];
/**
* @var array
*/
private $queryParams = [];
/**
* @var array
*/
private $optionalQueryParams = [];
/**
* RequestMatcher constructor.
*
* @param string $host
*/
private function __construct(string $host)
{
$this->host = $host;
}
/**
* @param string $host
*
* @return \RetailCrm\Test\RequestMatcher
*/
public static function createMatcher(string $host): RequestMatcher
{
return new self($host);
}
/**
* @param string $path
*
* @return RequestMatcher
*/
public function setPath(string $path): RequestMatcher
{
$this->path = $path;
return $this;
}
/**
* @param string $method
*
* @return RequestMatcher
*/
public function setMethod(string $method): RequestMatcher
{
$this->method = $method;
return $this;
}
/**
* @param string $scheme
*
* @return RequestMatcher
*/
public function setScheme(string $scheme): RequestMatcher
{
$this->scheme = $scheme;
return $this;
}
/**
* @param array $headers
*
* @return RequestMatcher
*/
public function setHeaders(array $headers): RequestMatcher
{
$this->headers = $headers;
return $this;
}
/**
* @param array $optionalHeaders
*
* @return RequestMatcher
*/
public function setOptionalHeaders(array $optionalHeaders): RequestMatcher
{
$this->optionalHeaders = $optionalHeaders;
return $this;
}
/**
* @param array $queryParams
*
* @return RequestMatcher
*/
public function setQueryParams(array $queryParams): RequestMatcher
{
$this->queryParams = $queryParams;
return $this;
}
/**
* @param array $optionalQueryParams
*
* @return RequestMatcher
*/
public function setOptionalQueryParams(array $optionalQueryParams): RequestMatcher
{
$this->optionalQueryParams = $optionalQueryParams;
return $this;
}
/**
* {@inheritdoc}
*/
public function matches(RequestInterface $request)
{
if ($this->scheme && strtoupper($request->getUri()->getScheme()) !== strtoupper($this->scheme)) {
return false;
}
if ($this->method && strtoupper($request->getMethod()) !== strtoupper($this->method)) {
return false;
}
if (null !== $this->path && !preg_match('{'.$this->path.'}', rawurldecode($request->getUri()->getPath()))) {
return false;
}
if (null !== $this->host && $this->host !== $request->getUri()->getHost()) {
return false;
}
if (!empty($this->headers) && count(array_diff_assoc($this->headers, $request->getHeaders())) > 0) {
return false;
}
if (!empty($this->queryParams)
&& count(array_diff_assoc($this->queryParams, $this->getQueryData($request->getUri()->getQuery()))) > 0
) {
return false;
}
if (!empty($this->optionalHeaders)
&& !$this->firstArrayPresentInSecond($this->optionalHeaders, $request->getHeaders())
) {
return false;
}
if (!empty($this->optionalQueryParams)
&& !$this->firstArrayPresentInSecond(
$this->optionalQueryParams,
$this->getQueryData($request->getUri()->getQuery())
)
) {
return false;
}
return true;
}
/**
* @param array $first
* @param array $second
*
* @return bool
*/
private function firstArrayPresentInSecond(array $first, array $second): bool
{
return count(array_diff_assoc($first, array_intersect_assoc($first, $second))) === 0;
}
/**
* @param string $query
*
* @return array
*/
private function getQueryData(string $query): array
{
$list = [];
parse_str($query, $list);
return $list;
}
}

View File

@ -6,6 +6,7 @@ use DateTime;
use Http\Client\Curl\Client as CurlClient;
use Http\Discovery\Psr17FactoryDiscovery;
use Http\Mock\Client as MockClient;
use InvalidArgumentException;
use Nyholm\Psr7\Factory\Psr17Factory;
use Psr\Container\ContainerInterface;
use Psr\Http\Client\ClientInterface;
@ -122,9 +123,10 @@ abstract class TestCase extends \PHPUnit\Framework\TestCase
/**
* @param int $code
* @param \RetailCrm\Model\Response\BaseResponse $response
* @param object|array|string $response
*
* @return \Psr\Http\Message\ResponseInterface
* @throws InvalidArgumentException
*/
protected function responseJson(int $code, $response): ResponseInterface
{
@ -132,10 +134,26 @@ abstract class TestCase extends \PHPUnit\Framework\TestCase
$serializer = $this->getContainer()->get(Constants::SERIALIZER);
$responseFactory = Psr17FactoryDiscovery::findResponseFactory();
$streamFactory = Psr17FactoryDiscovery::findStreamFactory();
$data = null;
switch (gettype($response)) {
case 'string':
$data = $streamFactory->createStream($response);
break;
case 'array':
case 'object':
$data = $streamFactory->createStream($serializer->serialize($response, 'json'));
break;
default:
throw new InvalidArgumentException(sprintf(
'Expected string, object, or array, got "%s"',
gettype($response)
));
}
return $responseFactory->createResponse($code)
->withHeader('Content-Type', 'application/json')
->withBody($streamFactory->createStream($serializer->serialize($response, 'json')));
->withBody($data);
}
/**

View File

@ -14,9 +14,9 @@ namespace RetailCrm\Tests\Component\JMS\Visitor\Deserialization;
use RetailCrm\Component\Constants;
use RetailCrm\Model\Entity\CategoryInfo;
use RetailCrm\Model\Response\AliExpressSolution\Data\SellerCategoryTreeQueryResponseData;
use RetailCrm\Model\Response\AliExpressSolution\Data\SellerCategoryTreeQueryResponseDataChildrenCategoryList;
use RetailCrm\Model\Response\AliExpressSolution\SellerCategoryTreeQueryResponse;
use RetailCrm\Model\Response\AliExpress\Data\SolutionSellerCategoryTreeQueryResponseData;
use RetailCrm\Model\Response\AliExpress\Data\SolutionSellerCategoryTreeQueryResponseDataChildrenCategoryList;
use RetailCrm\Model\Response\AliExpress\SolutionSellerCategoryTreeQueryResponse;
use RetailCrm\Test\TestCase;
/**
@ -65,12 +65,12 @@ EOF;
/** @var \JMS\Serializer\SerializerInterface $serializer */
$serializer = $this->getContainer()->get(Constants::SERIALIZER);
/** @var SellerCategoryTreeQueryResponse $result */
$result = $serializer->deserialize($json, SellerCategoryTreeQueryResponse::class, 'json');
/** @var SolutionSellerCategoryTreeQueryResponse $result */
$result = $serializer->deserialize($json, SolutionSellerCategoryTreeQueryResponse::class, 'json');
self::assertInstanceOf(SellerCategoryTreeQueryResponseData::class, $result->responseData);
self::assertInstanceOf(SolutionSellerCategoryTreeQueryResponseData::class, $result->responseData);
self::assertInstanceOf(
SellerCategoryTreeQueryResponseDataChildrenCategoryList::class,
SolutionSellerCategoryTreeQueryResponseDataChildrenCategoryList::class,
$result->responseData->childrenCategoryList
);
self::assertIsArray($result->responseData->childrenCategoryList->categoryInfo);

View File

@ -12,14 +12,23 @@
*/
namespace RetailCrm\Tests\TopClient;
use Http\Message\RequestMatcher\CallbackRequestMatcher;
use Psr\Http\Message\RequestInterface;
use RetailCrm\Builder\ClientBuilder;
use RetailCrm\Component\AppData;
use RetailCrm\Component\Constants;
use RetailCrm\Model\Entity\CategoryInfo;
use RetailCrm\Model\Request\AliExpress\PostproductRedefiningCategoryForecast;
use RetailCrm\Model\Request\AliExpress\SolutionSellerCategoryTreeQuery;
use RetailCrm\Model\Request\Taobao\HttpDnsGetRequest;
use RetailCrm\Model\Response\BaseResponse;
use RetailCrm\Model\Response\AliExpress\Data\SolutionSellerCategoryTreeQueryResponseData;
use RetailCrm\Model\Response\AliExpress\Data\SolutionSellerCategoryTreeQueryResponseDataChildrenCategoryList;
use RetailCrm\Model\Response\AliExpress\PostproductRedefiningCategoryForecastResponse;
use RetailCrm\Model\Response\AliExpress\SolutionSellerCategoryTreeQueryResponse;
use RetailCrm\Model\Response\ErrorResponseBody;
use RetailCrm\Test\ClosureRequestMatcher;
use RetailCrm\Model\Response\Taobao\HttpDnsGetResponse;
use RetailCrm\Test\TestCase;
use RetailCrm\Test\RequestMatcher;
/**
* Class ClientTest
@ -40,11 +49,11 @@ class ClientTest extends TestCase
$errorBody->msg = 'Mocked error';
$errorBody->subCode = 'subcode';
$errorBody->requestId = '1';
$errorResponse = new BaseResponse();
$errorResponse = new HttpDnsGetResponse();
$errorResponse->errorResponse = $errorBody;
$mockClient = self::getMockClient();
$mockClient->on(new ClosureRequestMatcher(function (RequestInterface $request) {
$mockClient->on(new CallbackRequestMatcher(function (RequestInterface $request) {
return true;
}), $this->responseJson(400, $errorResponse));
@ -71,4 +80,138 @@ class ClientTest extends TestCase
$this->expectExceptionMessage('Client only supports JSON mode, got `xml` mode');
$client->sendRequest($request);
}
public function testClientAliexpressSolutionSellerCategoryTreeQueryResponse()
{
$json = <<<'EOF'
{
"aliexpress_solution_seller_category_tree_query_response":{
"children_category_list":{
"category_info":[
{
"children_category_id":5090301,
"is_leaf_category":true,
"level":2,
"multi_language_names":"{ \"de\": \"Mobiltelefon\", \"ru\": \"Мобильные телефоны\", \"pt\": \"Telefonia\", \"in\": \"Ponsel\", \"en\": \"Mobile Phones\", \"it\": \"Telefoni cellulari\", \"fr\": \"Smartphones\", \"es\": \"Smartphones\", \"tr\": \"Cep Telefonu\", \"nl\": \"Mobiele telefoons\" }"
}
]
},
"is_success":true
}
}
EOF;
$expectedLangs = [
'de' => 'Mobiltelefon',
'ru' => 'Мобильные телефоны',
'pt' => 'Telefonia',
'in' => 'Ponsel',
'en' => 'Mobile Phones',
'it' => 'Telefoni cellulari',
'fr' => 'Smartphones',
'es' => 'Smartphones',
'tr' => 'Cep Telefonu',
'nl' => 'Mobiele telefoons'
];
$mock = self::getMockClient();
$mock->on(
RequestMatcher::createMatcher('api.taobao.com')
->setPath('/router/rest')
->setOptionalQueryParams([
'app_key' => 'appKey',
'method' => 'aliexpress.solution.seller.category.tree.query',
'category_id' => '5090300',
'filter_no_permission' => 1
]),
$this->responseJson(200, $json)
);
$client = ClientBuilder::create()
->setContainer($this->getContainer($mock))
->setAppData(new AppData(AppData::OVERSEAS_ENDPOINT, 'appKey', 'appSecret'))
->build();
$request = new SolutionSellerCategoryTreeQuery();
$request->categoryId = 5090300;
$request->filterNoPermission = true;
/** @var SolutionSellerCategoryTreeQueryResponse $response */
$result = $client->sendRequest($request);
self::assertInstanceOf(SolutionSellerCategoryTreeQueryResponseData::class, $result->responseData);
self::assertInstanceOf(
SolutionSellerCategoryTreeQueryResponseDataChildrenCategoryList::class,
$result->responseData->childrenCategoryList
);
self::assertIsArray($result->responseData->childrenCategoryList->categoryInfo);
self::assertCount(1, $result->responseData->childrenCategoryList->categoryInfo);
$info = $result->responseData->childrenCategoryList->categoryInfo[0];
self::assertInstanceOf(CategoryInfo::class, $info);
self::assertEquals(5090301, $info->childrenCategoryId);
self::assertTrue($info->isLeafCategory);
self::assertEquals(2, $info->level);
self::assertIsArray($info->multiLanguageNames);
foreach ($expectedLangs as $lang => $value) {
self::assertArrayHasKey($lang, $info->multiLanguageNames);
self::assertEquals($value, $info->multiLanguageNames[$lang]);
}
}
public function testClientAliexpressPostproductRedefiningCategoryForecast()
{
$json = <<<'EOF'
{
"aliexpress_postproduct_redefining_categoryforecast_response":{
"result":{
"error_message":"The result of dii is empty. It should have a correct JSON format data return.",
"category_suitability_list":{
"json":[
"N\/A"
]
},
"time_stamp":"20181101111211",
"error_code":24000011,
"success":true
}
}
}
EOF;
$mock = self::getMockClient();
$mock->on(
RequestMatcher::createMatcher('api.taobao.com')
->setPath('/router/rest')
->setOptionalQueryParams([
'app_key' => 'appKey',
'method' => 'aliexpress.postproduct.redefining.categoryforecast'
]),
$this->responseJson(200, $json)
);
$client = ClientBuilder::create()
->setContainer($this->getContainer($mock))
->setAppData(new AppData(AppData::OVERSEAS_ENDPOINT, 'appKey', 'appSecret'))
->build();
$request = new PostproductRedefiningCategoryForecast();
$request->subject = 'man t-shirt';
$request->locale = 'en';
/** @var PostproductRedefiningCategoryForecastResponse $response */
$response = $client->sendRequest($request);
self::assertInstanceOf(PostproductRedefiningCategoryForecastResponse::class, $response);
self::assertEquals(
"The result of dii is empty. It should have a correct JSON format data return.",
$response->responseData->result->errorMessage
);
self::assertEquals(
['N/A'],
$response->responseData->result->categorySuitabilityList->json
);
self::assertEquals('20181101111211', $response->responseData->result->timeStamp);
self::assertEquals('24000011', $response->responseData->result->errorCode);
self::assertTrue($response->responseData->result->success);
}
}