2020-09-28 17:18:21 +03:00
|
|
|
<?php
|
|
|
|
|
|
|
|
namespace RetailCrm\Test;
|
|
|
|
|
2020-09-29 13:10:54 +03:00
|
|
|
use DateTime;
|
2020-09-28 17:18:21 +03:00
|
|
|
use Psr\Container\ContainerInterface;
|
2020-09-29 13:10:54 +03:00
|
|
|
use RetailCrm\Component\AppData;
|
|
|
|
use RetailCrm\Component\Authenticator\TokenAuthenticator;
|
2020-09-28 17:18:21 +03:00
|
|
|
use RetailCrm\Component\Environment;
|
|
|
|
use RetailCrm\Factory\ContainerFactory;
|
2020-09-29 13:10:54 +03:00
|
|
|
use RetailCrm\Factory\FileItemFactory;
|
|
|
|
use RetailCrm\Interfaces\AppDataInterface;
|
|
|
|
use RetailCrm\Interfaces\AuthenticatorInterface;
|
2020-09-28 17:18:21 +03:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Class TestCase
|
|
|
|
*
|
|
|
|
* @category TestCase
|
|
|
|
* @package ${NAMESPACE}
|
|
|
|
* @author RetailDriver LLC <integration@retailcrm.ru>
|
|
|
|
* @license MIT
|
|
|
|
* @link http://retailcrm.ru
|
|
|
|
* @see https://help.retailcrm.ru
|
|
|
|
*/
|
|
|
|
class TestCase extends \PHPUnit\Framework\TestCase
|
|
|
|
{
|
|
|
|
private $container;
|
|
|
|
|
2020-09-29 13:10:54 +03:00
|
|
|
/**
|
|
|
|
* @param bool $recreate
|
|
|
|
*
|
|
|
|
* @return \Psr\Container\ContainerInterface
|
|
|
|
*/
|
|
|
|
protected function getContainer($recreate = false): ContainerInterface
|
2020-09-28 17:18:21 +03:00
|
|
|
{
|
|
|
|
if (null === $this->container || $recreate) {
|
|
|
|
$this->container = ContainerFactory::withEnv(Environment::TEST)
|
|
|
|
->withClient(new \GuzzleHttp\Client())
|
|
|
|
->create();
|
|
|
|
}
|
|
|
|
|
|
|
|
return $this->container;
|
|
|
|
}
|
2020-09-29 13:10:54 +03:00
|
|
|
|
|
|
|
/**
|
|
|
|
* @return \RetailCrm\Interfaces\AppDataInterface
|
|
|
|
*/
|
|
|
|
protected function getAppData(): AppDataInterface
|
|
|
|
{
|
|
|
|
return AppData::create(AppData::OVERSEAS_ENDPOINT, 'appKey', 'helloworld');
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @param string $appKey
|
|
|
|
* @param string $token
|
|
|
|
*
|
|
|
|
* @return \RetailCrm\Interfaces\AuthenticatorInterface
|
|
|
|
*/
|
|
|
|
protected function getAuthenticator(string $appKey = 'appKey', string $token = 'token'): AuthenticatorInterface
|
|
|
|
{
|
|
|
|
return new TokenAuthenticator($appKey, $token);
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @param string $signMethod
|
|
|
|
*
|
2020-09-29 13:18:18 +03:00
|
|
|
* @param bool $withFile
|
|
|
|
* @param bool $withDto
|
2020-09-29 13:10:54 +03:00
|
|
|
*
|
|
|
|
* @return \RetailCrm\Test\TestSignerRequest
|
|
|
|
*/
|
2020-09-29 13:18:18 +03:00
|
|
|
protected function getTestRequest(string $signMethod, bool $withFile = false, bool $withDto = false): TestSignerRequest
|
2020-09-29 13:10:54 +03:00
|
|
|
{
|
|
|
|
$request = new TestSignerRequest();
|
|
|
|
$request->method = 'aliexpress.solution.order.fulfill';
|
|
|
|
$request->appKey = '12345678';
|
|
|
|
$request->session = 'test';
|
|
|
|
$request->timestamp = DateTime::createFromFormat('Y-m-d H:i:s', '2016-01-01 12:00:00');
|
|
|
|
$request->signMethod = $signMethod;
|
|
|
|
$request->serviceName = 'SPAIN_LOCAL_CORREOS';
|
|
|
|
$request->outRef = '1000006270175804';
|
|
|
|
$request->sendType = 'all';
|
|
|
|
$request->logisticsNo = 'ES2019COM0000123456';
|
|
|
|
|
|
|
|
if ($withFile) {
|
|
|
|
/** @var FileItemFactory $factory */
|
|
|
|
$factory = $this->getContainer()->get(FileItemFactory::class);
|
|
|
|
$request->document = $factory->fromString(
|
|
|
|
'file.txt',
|
|
|
|
'The quick brown fox jumps over the lazy dog'
|
|
|
|
);
|
|
|
|
}
|
|
|
|
|
2020-09-29 13:18:18 +03:00
|
|
|
if ($withDto) {
|
|
|
|
$request->dto = new TestDto();
|
|
|
|
}
|
|
|
|
|
2020-09-29 13:10:54 +03:00
|
|
|
return $request;
|
|
|
|
}
|
2020-09-28 17:18:21 +03:00
|
|
|
}
|