2020-09-28 17:18:21 +03:00
|
|
|
<?php
|
|
|
|
|
|
|
|
/**
|
|
|
|
* PHP version 7.3
|
|
|
|
*
|
|
|
|
* @category RequestSigner
|
|
|
|
* @package RetailCrm\Tests\Service
|
|
|
|
*/
|
|
|
|
namespace RetailCrm\Tests\Service;
|
|
|
|
|
|
|
|
use RetailCrm\Component\AppData;
|
|
|
|
use RetailCrm\Component\Constants;
|
|
|
|
use RetailCrm\Interfaces\AppDataInterface;
|
|
|
|
use RetailCrm\Interfaces\RequestSignerInterface;
|
2020-10-06 12:47:38 +03:00
|
|
|
use RetailCrm\Interfaces\TopRequestFactoryInterface;
|
2020-10-02 12:19:50 +03:00
|
|
|
use RetailCrm\Model\Enum\AvailableSignMethods;
|
2020-09-28 17:18:21 +03:00
|
|
|
use RetailCrm\Test\TestCase;
|
|
|
|
use RetailCrm\Test\TestSignerRequest;
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Class RequestSigner
|
|
|
|
*
|
|
|
|
* @category RequestSigner
|
|
|
|
* @package RetailCrm\Tests\Service
|
|
|
|
*/
|
|
|
|
class RequestSignerTest extends TestCase
|
|
|
|
{
|
|
|
|
/**
|
|
|
|
* @dataProvider signDataProvider
|
|
|
|
*
|
2020-10-06 12:47:38 +03:00
|
|
|
* @param array $request
|
2020-09-28 17:18:21 +03:00
|
|
|
* @param \RetailCrm\Interfaces\AppDataInterface $appData
|
|
|
|
* @param string $expectedHash
|
2020-10-06 12:47:38 +03:00
|
|
|
*
|
|
|
|
* @throws \RetailCrm\Component\Exception\NotImplementedException
|
2020-09-28 17:18:21 +03:00
|
|
|
*/
|
2020-10-06 12:47:38 +03:00
|
|
|
public function testSign(array $request, AppDataInterface $appData, string $expectedHash): void
|
2020-09-28 17:18:21 +03:00
|
|
|
{
|
|
|
|
/** @var RequestSignerInterface $signer */
|
2020-09-29 15:18:03 +03:00
|
|
|
$signer = $this->getContainer()->get(RequestSignerInterface::class);
|
2020-09-28 17:18:21 +03:00
|
|
|
|
2020-10-06 12:47:38 +03:00
|
|
|
self::assertEquals($expectedHash, $signer->generateSign($request, $appData, $request['sign_method']));
|
2020-09-28 17:18:21 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
public function signDataProvider(): array
|
|
|
|
{
|
2020-10-06 12:47:38 +03:00
|
|
|
/** @var TopRequestFactoryInterface $factory */
|
|
|
|
$factory = $this->getContainer()->get(TopRequestFactoryInterface::class);
|
2020-09-29 13:10:54 +03:00
|
|
|
$appData = $this->getAppData();
|
2020-09-28 17:18:21 +03:00
|
|
|
|
|
|
|
return [
|
|
|
|
[
|
2020-10-06 12:47:38 +03:00
|
|
|
$factory->getRequestArray($this->getTestRequest(AvailableSignMethods::MD5)),
|
2020-09-28 17:18:21 +03:00
|
|
|
$appData,
|
2020-10-06 12:47:38 +03:00
|
|
|
'4BC79C5FAA1B5E254E95A97E65BACEAB'
|
2020-09-28 17:18:21 +03:00
|
|
|
],
|
|
|
|
[
|
2020-10-06 12:47:38 +03:00
|
|
|
$factory->getRequestArray($this->getTestRequest(AvailableSignMethods::HMAC_MD5)),
|
2020-09-29 13:10:54 +03:00
|
|
|
$appData,
|
2020-10-06 12:47:38 +03:00
|
|
|
'497FA7FCAD98F4F335EFAE2451F8291D'
|
2020-09-29 13:10:54 +03:00
|
|
|
],
|
|
|
|
[
|
2020-10-06 12:47:38 +03:00
|
|
|
$factory->getRequestArray($this->getTestRequest(AvailableSignMethods::MD5, true)),
|
2020-09-29 13:10:54 +03:00
|
|
|
$appData,
|
2020-10-06 12:47:38 +03:00
|
|
|
'4BC79C5FAA1B5E254E95A97E65BACEAB'
|
2020-09-29 13:10:54 +03:00
|
|
|
],
|
|
|
|
[
|
2020-10-06 12:47:38 +03:00
|
|
|
$factory->getRequestArray($this->getTestRequest(AvailableSignMethods::HMAC_MD5, true)),
|
2020-09-28 17:18:21 +03:00
|
|
|
$appData,
|
2020-10-06 12:47:38 +03:00
|
|
|
'497FA7FCAD98F4F335EFAE2451F8291D'
|
2020-09-28 17:18:21 +03:00
|
|
|
]
|
|
|
|
];
|
|
|
|
}
|
|
|
|
}
|