1
0
mirror of synced 2024-12-03 18:06:03 +03:00
aliexpress-top-client/tests/RetailCrm/Tests/Service/RequestSignerTest.php

83 lines
2.6 KiB
PHP

<?php
/**
* PHP version 7.3
*
* @category RequestSigner
* @package RetailCrm\Tests\Service
* @author RetailCRM <integration@retailcrm.ru>
* @license MIT
* @link http://retailcrm.ru
* @see http://help.retailcrm.ru
*/
namespace RetailCrm\Tests\Service;
use RetailCrm\Component\AppData;
use RetailCrm\Component\Constants;
use RetailCrm\Interfaces\AppDataInterface;
use RetailCrm\Interfaces\RequestSignerInterface;
use RetailCrm\Interfaces\TopRequestFactoryInterface;
use RetailCrm\Model\Enum\AvailableSignMethods;
use RetailCrm\Test\TestCase;
use RetailCrm\Test\TestSignerRequest;
/**
* Class RequestSigner
*
* @category RequestSigner
* @package RetailCrm\Tests\Service
* @author RetailDriver LLC <integration@retailcrm.ru>
* @license MIT
* @link http://retailcrm.ru
* @see https://help.retailcrm.ru
*/
class RequestSignerTest extends TestCase
{
/**
* @dataProvider signDataProvider
*
* @param array $request
* @param \RetailCrm\Interfaces\AppDataInterface $appData
* @param string $expectedHash
*
* @throws \RetailCrm\Component\Exception\NotImplementedException
*/
public function testSign(array $request, AppDataInterface $appData, string $expectedHash): void
{
/** @var RequestSignerInterface $signer */
$signer = $this->getContainer()->get(RequestSignerInterface::class);
self::assertEquals($expectedHash, $signer->generateSign($request, $appData, $request['sign_method']));
}
public function signDataProvider(): array
{
/** @var TopRequestFactoryInterface $factory */
$factory = $this->getContainer()->get(TopRequestFactoryInterface::class);
$appData = $this->getAppData();
return [
[
$factory->getRequestArray($this->getTestRequest(AvailableSignMethods::MD5)),
$appData,
'4BC79C5FAA1B5E254E95A97E65BACEAB'
],
[
$factory->getRequestArray($this->getTestRequest(AvailableSignMethods::HMAC_MD5)),
$appData,
'497FA7FCAD98F4F335EFAE2451F8291D'
],
[
$factory->getRequestArray($this->getTestRequest(AvailableSignMethods::MD5, true)),
$appData,
'4BC79C5FAA1B5E254E95A97E65BACEAB'
],
[
$factory->getRequestArray($this->getTestRequest(AvailableSignMethods::HMAC_MD5, true)),
$appData,
'497FA7FCAD98F4F335EFAE2451F8291D'
]
];
}
}