From 387c379b2bd24bfc410df0ec9dfd3c7af1d83552 Mon Sep 17 00:00:00 2001 From: mustapayev Date: Fri, 27 Sep 2024 09:44:27 +0200 Subject: [PATCH] tests - replace crypt instances with mocks --- .../GarantiPosRequestDataMapperTest.php | 463 +++++++++++------- .../PayFlexCPV4PosRequestDataMapperTest.php | 25 +- .../PosNetRequestDataMapperTest.php | 41 +- .../PosNetV1PosRequestDataMapperTest.php | 81 ++- .../VakifKatilimPosRequestDataMapperTest.php | 155 +++++- .../AkbankPosResponseDataMapperTest.php | 10 +- .../EstPosResponseDataMapperTest.php | 20 +- .../GarantiPosResponseDataMapperTest.php | 20 +- .../InterPosResponseDataMapperTest.php | 21 +- .../KuveytPosResponseDataMapperTest.php | 19 +- .../PayFlexCPV4PosResponseDataMapperTest.php | 20 +- .../PayFlexV4PosResponseDataMapperTest.php | 10 +- .../PayForPosResponseDataMapperTest.php | 16 +- .../PosNetResponseDataMapperTest.php | 19 +- .../PosNetV1PosResponseDataMapperTest.php | 21 +- .../ToslaPosResponseDataMapperTest.php | 20 +- .../VakifKatilimPosResponseDataMapperTest.php | 18 +- 17 files changed, 691 insertions(+), 288 deletions(-) diff --git a/tests/Unit/DataMapper/RequestDataMapper/GarantiPosRequestDataMapperTest.php b/tests/Unit/DataMapper/RequestDataMapper/GarantiPosRequestDataMapperTest.php index 5a6e3962..5a583109 100644 --- a/tests/Unit/DataMapper/RequestDataMapper/GarantiPosRequestDataMapperTest.php +++ b/tests/Unit/DataMapper/RequestDataMapper/GarantiPosRequestDataMapperTest.php @@ -5,21 +5,19 @@ namespace Mews\Pos\Tests\Unit\DataMapper\RequestDataMapper; +use Mews\Pos\Crypt\CryptInterface; use Mews\Pos\DataMapper\RequestDataMapper\GarantiPosRequestDataMapper; -use Mews\Pos\Entity\Account\AbstractPosAccount; use Mews\Pos\Entity\Account\GarantiPosAccount; use Mews\Pos\Entity\Card\CreditCardInterface; use Mews\Pos\Event\Before3DFormHashCalculatedEvent; use Mews\Pos\Exceptions\UnsupportedTransactionTypeException; use Mews\Pos\Factory\AccountFactory; use Mews\Pos\Factory\CreditCardFactory; -use Mews\Pos\Factory\CryptFactory; use Mews\Pos\Gateways\GarantiPos; use Mews\Pos\PosInterface; use PHPUnit\Framework\MockObject\MockObject; use PHPUnit\Framework\TestCase; use Psr\EventDispatcher\EventDispatcherInterface; -use Psr\Log\NullLogger; /** * @covers \Mews\Pos\DataMapper\RequestDataMapper\GarantiPosRequestDataMapper @@ -33,11 +31,12 @@ class GarantiPosRequestDataMapperTest extends TestCase private GarantiPosRequestDataMapper $requestDataMapper; - private array $order; - /** @var EventDispatcherInterface & MockObject */ private EventDispatcherInterface $dispatcher; + /** @var CryptInterface & MockObject */ + private CryptInterface $crypt; + protected function setUp(): void { parent::setUp(); @@ -54,21 +53,9 @@ protected function setUp(): void '123qweASD/' ); - $this->order = [ - 'id' => 'order222', - 'amount' => '100.25', - 'installment' => 0, - 'currency' => PosInterface::CURRENCY_TRY, - 'success_url' => 'https://domain.com/success', - 'fail_url' => 'https://domain.com/fail_url', - 'lang' => 'tr', - 'ip' => '156.155.154.153', - ]; - - $this->dispatcher = $this->createMock(EventDispatcherInterface::class); - - $crypt = CryptFactory::createGatewayCrypt(GarantiPos::class, new NullLogger()); - $this->requestDataMapper = new GarantiPosRequestDataMapper($this->dispatcher, $crypt); + $this->dispatcher = $this->createMock(EventDispatcherInterface::class); + $this->crypt = $this->createMock(CryptInterface::class); + $this->requestDataMapper = new GarantiPosRequestDataMapper($this->dispatcher, $this->crypt); $this->requestDataMapper->setTestMode(true); $this->card = CreditCardFactory::create('5555444433332222', '22', '01', '123', 'ahmet'); @@ -138,16 +125,21 @@ public function testMapInstallment($installment, $expected): void } /** - * @return void + * @dataProvider nonSecurePaymentPostRequestDataDataProvider */ - public function testCreateNonSecurePostAuthPaymentRequestData(): void + public function testCreateNonSecurePostAuthPaymentRequestData(array $order, array $expected): void { - $this->order['ref_ret_num'] = '831803579226'; + $hashCalculationData = $expected; + $hashCalculationData['Terminal']['HashData'] = ''; - $actual = $this->requestDataMapper->createNonSecurePostAuthPaymentRequestData($this->account, $this->order); + $this->crypt->expects(self::once()) + ->method('createHash') + ->with($this->account, $hashCalculationData) + ->willReturn($expected['Terminal']['HashData']); - $expectedData = $this->getSampleNonSecurePaymentPostRequestData($this->account, $this->order); - $this->assertEquals($expectedData, $actual); + $actual = $this->requestDataMapper->createNonSecurePostAuthPaymentRequestData($this->account, $order); + + $this->assertSame($expected, $actual); } /** @@ -155,6 +147,14 @@ public function testCreateNonSecurePostAuthPaymentRequestData(): void */ public function testCreateNonSecurePaymentRequestData(array $order, string $txType, CreditCardInterface $card, array $expectedData): void { + $hashCalculationData = $expectedData; + $hashCalculationData['Terminal']['HashData'] = ''; + + $this->crypt->expects(self::once()) + ->method('createHash') + ->with($this->account, $hashCalculationData) + ->willReturn($expectedData['Terminal']['HashData']); + $actual = $this->requestDataMapper->createNonSecurePaymentRequestData( $this->account, $order, @@ -166,23 +166,21 @@ public function testCreateNonSecurePaymentRequestData(array $order, string $txTy } /** - * @return void + * @dataProvider cancelRequestDataProvider */ - public function testCreateCancelRequestData(): void + public function testCreateCancelRequestData(array $order, array $expectedData): void { - $order = [ - 'id' => '2020110828BC', - 'ip' => '127.15.15.1', - 'currency' => PosInterface::CURRENCY_TRY, - 'amount' => '1.00', - 'ref_ret_num' => '831803579226', - 'installment' => 0, - ]; + $hashCalculationData = $expectedData; + $hashCalculationData['Terminal']['HashData'] = ''; + + $this->crypt->expects(self::once()) + ->method('createHash') + ->with($this->account, $hashCalculationData) + ->willReturn($expectedData['Terminal']['HashData']); $actual = $this->requestDataMapper->createCancelRequestData($this->account, $order); - $expectedData = $this->getSampleCancelXMLData($this->account, $order); - $this->assertEquals($expectedData, $actual); + $this->assertSame($expectedData, $actual); } /** @@ -190,9 +188,17 @@ public function testCreateCancelRequestData(): void */ public function testCreateOrderHistoryRequestData(array $order, array $expectedData): void { + $hashCalculationData = $expectedData; + $hashCalculationData['Terminal']['HashData'] = ''; + + $this->crypt->expects(self::once()) + ->method('createHash') + ->with($this->account, $hashCalculationData) + ->willReturn($expectedData['Terminal']['HashData']); + $actual = $this->requestDataMapper->createOrderHistoryRequestData($this->account, $order); - $this->assertEquals($expectedData, $actual); + $this->assertSame($expectedData, $actual); } /** @@ -200,6 +206,14 @@ public function testCreateOrderHistoryRequestData(array $order, array $expectedD */ public function testCreateHistoryRequestData(array $data, array $expectedData): void { + $hashCalculationData = $expectedData; + $hashCalculationData['Terminal']['HashData'] = ''; + + $this->crypt->expects(self::once()) + ->method('createHash') + ->with($this->account, $hashCalculationData) + ->willReturn($expectedData['Terminal']['HashData']); + $actualData = $this->requestDataMapper->createHistoryRequestData($this->account, $data); \ksort($expectedData); @@ -213,49 +227,31 @@ public function testCreateHistoryRequestData(array $data, array $expectedData): */ public function testCreate3DPaymentRequestData(GarantiPosAccount $garantiPosAccount, array $order, array $responseData, array $expected): void { + $hashCalculationData = $expected; + $hashCalculationData['Terminal']['HashData'] = ''; + + $this->crypt->expects(self::once()) + ->method('createHash') + ->with($this->account, $hashCalculationData) + ->willReturn($expected['Terminal']['HashData']); + $actual = $this->requestDataMapper->create3DPaymentRequestData($this->account, $order, '', $responseData); $this->assertEquals($expected, $actual); } /** - * @return void + * @dataProvider threeDFormDataProvider */ - public function testGet3DFormData(): void + public function testGet3DFormData( + array $order, + string $gatewayURL, + string $txType, + string $paymentModel, + bool $isWithCard, + array $expected + ): void { - $account = $this->account; - $gatewayURL = 'https://sanalposprovtest.garantibbva.com.tr/servlet/gt3dengine'; - $inputs = [ - 'secure3dsecuritylevel' => '3D', - 'mode' => 'TEST', - 'apiversion' => '512', - 'terminalprovuserid' => $account->getUsername(), - 'terminaluserid' => $account->getUsername(), - 'terminalmerchantid' => $account->getClientId(), - 'terminalid' => $account->getTerminalId(), - 'txntype' => 'sales', - 'txnamount' => '10025', - 'txncurrencycode' => '949', - 'txninstallmentcount' => '', - 'orderid' => $this->order['id'], - 'successurl' => $this->order['success_url'], - 'errorurl' => $this->order['fail_url'], - 'customeripaddress' => $this->order['ip'], - 'secure3dhash' => '372D6CB20B2B699D0A6667DFF46E3AA8CF3F9D8C2BB69A7C411895151FFCFAAB5277CCFE3B3A06035FEEFBFBFD40C79DBE51DBF867D0A24B37335A28F0CEFDE2', - 'cardnumber' => $this->card->getNumber(), - 'cardexpiredatemonth' => '01', - 'cardexpiredateyear' => '22', - 'cardcvv2' => $this->card->getCvv(), - ]; - - $form = [ - 'inputs' => $inputs, - 'method' => 'POST', - 'gateway' => $gatewayURL, - ]; - - $txType = PosInterface::TX_TYPE_PAY_AUTH; - $paymentModel = PosInterface::MODEL_3D_SECURE; $this->dispatcher->expects(self::once()) ->method('dispatch') ->with($this->callback(static fn($dispatchedEvent): bool => $dispatchedEvent instanceof Before3DFormHashCalculatedEvent @@ -264,53 +260,67 @@ public function testGet3DFormData(): void && $paymentModel === $dispatchedEvent->getPaymentModel() && count($dispatchedEvent->getFormInputs()) > 3)); + $hashCalculationData = $expected['inputs']; + unset($hashCalculationData['secure3dhash']); + + $this->crypt->expects(self::once()) + ->method('create3DHash') + ->with($this->account, $hashCalculationData) + ->willReturn($expected['inputs']['secure3dhash']); + $actual = $this->requestDataMapper->create3DFormData( $this->account, - $this->order, + $order, $paymentModel, $txType, $gatewayURL, - $this->card + $isWithCard ? $this->card : null ); - //test without card - $this->assertEquals($form, $actual); + $this->assertSame($expected, $actual); } /** - * @return void + * @dataProvider statusRequestDataDataProvider */ - public function testCreateStatusRequestData(): void + public function testCreateStatusRequestData(array $order, array $expected): void { - $order = [ - 'id' => '2020110828BC', - 'ip' => '127.15.15.1', - 'installment' => 0, - 'currency' => PosInterface::CURRENCY_TRY, - 'amount' => 1, - ]; + $hashCalculationData = $expected; + $hashCalculationData['Terminal']['HashData'] = ''; + + $this->crypt->expects(self::once()) + ->method('createHash') + ->with($this->account, $hashCalculationData) + ->willReturn($expected['Terminal']['HashData']); $actualData = $this->requestDataMapper->createStatusRequestData($this->account, $order); - $expectedData = $this->getSampleStatusRequestData($this->account, $order); - $this->assertEquals($expectedData, $actualData); + $this->assertSame($expected, $actualData); } /** * @dataProvider refundOrderDataProvider */ - public function testCreateRefundRequestData(array $order, string $txType, array $expectedData): void + public function testCreateRefundRequestData(array $order, string $txType, array $expected): void { + $hashCalculationData = $expected; + $hashCalculationData['Terminal']['HashData'] = ''; + + $this->crypt->expects(self::once()) + ->method('createHash') + ->with($this->account, $hashCalculationData) + ->willReturn($expected['Terminal']['HashData']); + $actual = $this->requestDataMapper->createRefundRequestData($this->account, $order, $txType); \ksort($actual); - \ksort($expectedData); - $this->assertSame($expectedData, $actual); + \ksort($expected); + $this->assertSame($expected, $actual); } public function testCreateRefundRequestDataWithoutRefundCredentials(): void { - $this->account = AccountFactory::createGarantiPosAccount( + $account = AccountFactory::createGarantiPosAccount( 'garanti', '7000679', 'PROVAUT', @@ -319,7 +329,7 @@ public function testCreateRefundRequestDataWithoutRefundCredentials(): void PosInterface::MODEL_3D_SECURE, '12345678', ); - $order = [ + $order = [ 'id' => '2020110828BC', 'ip' => '127.15.15.1', 'currency' => PosInterface::CURRENCY_TRY, @@ -330,44 +340,128 @@ public function testCreateRefundRequestDataWithoutRefundCredentials(): void $this->expectException(\LogicException::class); $this->requestDataMapper->createRefundRequestData( - $this->account, + $account, $order, PosInterface::TX_TYPE_REFUND ); } - /** - * @param GarantiPosAccount $posAccount - * @param $order - * - * @return array - */ - private function getSampleCancelXMLData(AbstractPosAccount $posAccount, array $order): array + public static function threeDFormDataProvider(): array { + $order = [ + 'id' => 'order222', + 'amount' => '100.25', + 'installment' => 0, + 'currency' => PosInterface::CURRENCY_TRY, + 'success_url' => 'https://domain.com/success', + 'fail_url' => 'https://domain.com/fail_url', + 'lang' => 'tr', + 'ip' => '156.155.154.153', + ]; + return [ - 'Mode' => 'TEST', - 'Version' => '512', - 'Terminal' => [ - 'ProvUserID' => $posAccount->getRefundUsername(), - 'UserID' => $posAccount->getRefundUsername(), - 'HashData' => '35E8410A78E24949D78F5E025B5E05AF470B01385A2ECBFEE6C5B3CDACFF78011D387ECAFDCE4B8453D80D35C2F344F3DAA6F2EF9143079F64DE88401EC5E4F5', - 'ID' => $posAccount->getTerminalId(), - 'MerchantID' => $posAccount->getClientId(), - ], - 'Customer' => [ - 'IPAddress' => $order['ip'], + 'without_card' => [ + 'order' => $order, + 'gatewayUrl' => 'https://sanalposprovtest.garantibbva.com.tr/servlet/gt3dengine', + 'txType' => PosInterface::TX_TYPE_PAY_AUTH, + 'paymentModel' => PosInterface::MODEL_3D_SECURE, + 'isWithCard' => false, + 'expected' => [ + 'gateway' => 'https://sanalposprovtest.garantibbva.com.tr/servlet/gt3dengine', + 'method' => 'POST', + 'inputs' => [ + 'secure3dsecuritylevel' => '3D', + 'mode' => 'TEST', + 'apiversion' => '512', + 'terminalprovuserid' => 'PROVAUT', + 'terminaluserid' => 'PROVAUT', + 'terminalmerchantid' => '7000679', + 'terminalid' => '30691298', + 'txntype' => 'sales', + 'txnamount' => '10025', + 'txncurrencycode' => '949', + 'txninstallmentcount' => '', + 'orderid' => 'order222', + 'successurl' => 'https://domain.com/success', + 'errorurl' => 'https://domain.com/fail_url', + 'customeripaddress' => '156.155.154.153', + 'secure3dhash' => '372D6CB20B2B699D0A6667DFF46E3AA8CF3F9D8C2BB69A7C411895151FFCFAAB5277CCFE3B3A06035FEEFBFBFD40C79DBE51DBF867D0A24B37335A28F0CEFDE2', + ], + ], ], - 'Order' => [ - 'OrderID' => $order['id'], + 'with_card' => [ + 'order' => $order, + 'gatewayUrl' => 'https://sanalposprovtest.garantibbva.com.tr/servlet/gt3dengine', + 'txType' => PosInterface::TX_TYPE_PAY_AUTH, + 'paymentModel' => PosInterface::MODEL_3D_SECURE, + 'isWithCard' => true, + 'expected' => [ + 'gateway' => 'https://sanalposprovtest.garantibbva.com.tr/servlet/gt3dengine', + 'method' => 'POST', + 'inputs' => [ + 'secure3dsecuritylevel' => '3D', + 'mode' => 'TEST', + 'apiversion' => '512', + 'terminalprovuserid' => 'PROVAUT', + 'terminaluserid' => 'PROVAUT', + 'terminalmerchantid' => '7000679', + 'terminalid' => '30691298', + 'txntype' => 'sales', + 'txnamount' => '10025', + 'txncurrencycode' => '949', + 'txninstallmentcount' => '', + 'orderid' => 'order222', + 'successurl' => 'https://domain.com/success', + 'errorurl' => 'https://domain.com/fail_url', + 'customeripaddress' => '156.155.154.153', + 'cardnumber' => '5555444433332222', + 'cardexpiredatemonth' => '01', + 'cardexpiredateyear' => '22', + 'cardcvv2' => '123', + 'secure3dhash' => '372D6CB20B2B699D0A6667DFF46E3AA8CF3F9D8C2BB69A7C411895151FFCFAAB5277CCFE3B3A06035FEEFBFBFD40C79DBE51DBF867D0A24B37335A28F0CEFDE2', + ], + ], ], - 'Transaction' => [ - 'Type' => 'void', - 'InstallmentCnt' => '', - 'Amount' => 100, - 'CurrencyCode' => '949', - 'CardholderPresentCode' => '0', - 'MotoInd' => 'N', - 'OriginalRetrefNum' => $order['ref_ret_num'], + ]; + } + + public static function cancelRequestDataProvider(): array + { + $order = [ + 'id' => '2020110828BC', + 'ip' => '127.0.0.1', + 'ref_ret_num' => '831803579226', + ]; + + return [ + [ + 'order' => $order, + 'expected' => [ + 'Mode' => 'TEST', + 'Version' => '512', + 'Terminal' => [ + 'ProvUserID' => 'PROVRFN', + 'UserID' => 'PROVRFN', + 'HashData' => '35E8410A78E24949D78F5E025B5E05AF470B01385A2ECBFEE6C5B3CDACFF78011D387ECAFDCE4B8453D80D35C2F344F3DAA6F2EF9143079F64DE88401EC5E4F5', + 'ID' => '30691298', + 'MerchantID' => '7000679', + ], + 'Customer' => [ + 'IPAddress' => '127.0.0.1', + ], + 'Order' => [ + 'OrderID' => '2020110828BC', + ], + 'Transaction' => [ + 'Type' => 'void', + 'InstallmentCnt' => '', + 'Amount' => 100, + 'CurrencyCode' => '949', + 'CardholderPresentCode' => '0', + 'MotoInd' => 'N', + 'OriginalRetrefNum' => '831803579226', + ], + ], ], ]; } @@ -480,70 +574,81 @@ public static function nonSecurePaymentRequestDataDataProvider(): array ]; } - /** - * @param GarantiPosAccount $posAccount - * @param array $order - * - * @return array - */ - private function getSampleNonSecurePaymentPostRequestData(AbstractPosAccount $posAccount, array $order): array + public static function nonSecurePaymentPostRequestDataDataProvider(): array { + $order = [ + 'id' => 'order222', + 'amount' => 100.25, + 'currency' => PosInterface::CURRENCY_TRY, + 'ip' => '127.0.0.1', + 'ref_ret_num' => '831803579226', + ]; + return [ - 'Mode' => 'TEST', - 'Version' => '512', - 'Terminal' => [ - 'ProvUserID' => $posAccount->getUsername(), - 'UserID' => $posAccount->getUsername(), - 'HashData' => '0CFE09F107274C6A07292DA061A4EECAB0F5F0CF87F831F2D3626A3346A941126C52D1D95A3B77ADF5AC348B3D25C76BA5D8D98A29557D087D3367BFFACCD25C', - 'ID' => $posAccount->getTerminalId(), - 'MerchantID' => $posAccount->getClientId(), - ], - 'Customer' => [ - 'IPAddress' => $order['ip'], - ], - 'Order' => [ - 'OrderID' => $order['id'], - ], - 'Transaction' => [ - 'Type' => 'postauth', - 'Amount' => 10025, - 'CurrencyCode' => '949', - 'OriginalRetrefNum' => $order['ref_ret_num'], + [ + 'order' => $order, + 'expected' => [ + 'Mode' => 'TEST', + 'Version' => '512', + 'Terminal' => [ + 'ProvUserID' => 'PROVAUT', + 'UserID' => 'PROVAUT', + 'HashData' => '', + 'ID' => '30691298', + 'MerchantID' => '7000679', + ], + 'Customer' => [ + 'IPAddress' => '127.0.0.1', + ], + 'Order' => [ + 'OrderID' => 'order222', + ], + 'Transaction' => [ + 'Type' => 'postauth', + 'Amount' => 10025, + 'CurrencyCode' => '949', + 'OriginalRetrefNum' => '831803579226', + ], + ], ], ]; } - /** - * @param GarantiPosAccount $posAccount - * @param array $order - * - * @return array - */ - private function getSampleStatusRequestData(AbstractPosAccount $posAccount, array $order): array + public static function statusRequestDataDataProvider(): array { + $order = [ + 'id' => '2020110828BC', + 'ip' => '127.15.15.1', + ]; + return [ - 'Mode' => 'TEST', - 'Version' => '512', - 'Terminal' => [ - 'ProvUserID' => $posAccount->getUsername(), - 'UserID' => $posAccount->getUsername(), - 'HashData' => '35E8410A78E24949D78F5E025B5E05AF470B01385A2ECBFEE6C5B3CDACFF78011D387ECAFDCE4B8453D80D35C2F344F3DAA6F2EF9143079F64DE88401EC5E4F5', - 'ID' => $posAccount->getTerminalId(), - 'MerchantID' => $posAccount->getClientId(), - ], - 'Customer' => [ - 'IPAddress' => $order['ip'], - ], - 'Order' => [ - 'OrderID' => $order['id'], - ], - 'Transaction' => [ - 'Type' => 'orderinq', - 'InstallmentCnt' => '', - 'Amount' => 100, - 'CurrencyCode' => '949', - 'CardholderPresentCode' => '0', - 'MotoInd' => 'N', + [ + 'order' => $order, + 'expected' => [ + 'Mode' => 'TEST', + 'Version' => '512', + 'Terminal' => [ + 'ProvUserID' => 'PROVAUT', + 'UserID' => 'PROVAUT', + 'HashData' => '35E8410A78E24949D78F5E025B5E05AF470B01385A2ECBFEE6C5B3CDACFF78011D387ECAFDCE4B8453D80D35C2F344F3DAA6F2EF9143079F64DE88401EC5E4F5', + 'ID' => '30691298', + 'MerchantID' => '7000679', + ], + 'Customer' => [ + 'IPAddress' => '127.15.15.1', + ], + 'Order' => [ + 'OrderID' => '2020110828BC', + ], + 'Transaction' => [ + 'Type' => 'orderinq', + 'InstallmentCnt' => '', + 'Amount' => 100, + 'CurrencyCode' => '949', + 'CardholderPresentCode' => '0', + 'MotoInd' => 'N', + ], + ], ], ]; } diff --git a/tests/Unit/DataMapper/RequestDataMapper/PayFlexCPV4PosRequestDataMapperTest.php b/tests/Unit/DataMapper/RequestDataMapper/PayFlexCPV4PosRequestDataMapperTest.php index 920c0b15..cf22531a 100644 --- a/tests/Unit/DataMapper/RequestDataMapper/PayFlexCPV4PosRequestDataMapperTest.php +++ b/tests/Unit/DataMapper/RequestDataMapper/PayFlexCPV4PosRequestDataMapperTest.php @@ -5,6 +5,7 @@ namespace Mews\Pos\Tests\Unit\DataMapper\RequestDataMapper; +use Mews\Pos\Crypt\CryptInterface; use Mews\Pos\DataMapper\RequestDataMapper\PayFlexCPV4PosRequestDataMapper; use Mews\Pos\Entity\Account\AbstractPosAccount; use Mews\Pos\Entity\Account\PayFlexAccount; @@ -13,13 +14,10 @@ use Mews\Pos\Exceptions\UnsupportedTransactionTypeException; use Mews\Pos\Factory\AccountFactory; use Mews\Pos\Factory\CreditCardFactory; -use Mews\Pos\Factory\CryptFactory; -use Mews\Pos\Gateways\PayFlexCPV4Pos; use Mews\Pos\PosInterface; use PHPUnit\Framework\MockObject\MockObject; use PHPUnit\Framework\TestCase; use Psr\EventDispatcher\EventDispatcherInterface; -use Psr\Log\NullLogger; /** * @covers \Mews\Pos\DataMapper\RequestDataMapper\PayFlexCPV4PosRequestDataMapper @@ -34,6 +32,9 @@ class PayFlexCPV4PosRequestDataMapperTest extends TestCase /** @var EventDispatcherInterface & MockObject */ private EventDispatcherInterface $dispatcher; + /** @var CryptInterface & MockObject */ + private CryptInterface $crypt; + protected function setUp(): void { parent::setUp(); @@ -47,8 +48,8 @@ protected function setUp(): void ); $this->dispatcher = $this->createMock(EventDispatcherInterface::class); - $crypt = CryptFactory::createGatewayCrypt(PayFlexCPV4Pos::class, new NullLogger()); - $this->requestDataMapper = new PayFlexCPV4PosRequestDataMapper($this->dispatcher, $crypt); + $this->crypt = $this->createMock(CryptInterface::class); + $this->requestDataMapper = new PayFlexCPV4PosRequestDataMapper($this->dispatcher, $this->crypt); } /** @@ -129,6 +130,14 @@ public function testMapInstallment($installment, $expected): void */ public function testCreate3DEnrollmentCheckData(AbstractPosAccount $posAccount, array $order, string $txType, ?CreditCard $creditCard, array $expectedData): void { + $hashCalculationData = $expectedData; + unset($hashCalculationData['HashedData']); + + $this->crypt->expects(self::once()) + ->method('create3DHash') + ->with($this->account, $hashCalculationData) + ->willReturn($expectedData['HashedData']); + $actual = $this->requestDataMapper->create3DEnrollmentCheckRequestData( $posAccount, $order, @@ -136,7 +145,7 @@ public function testCreate3DEnrollmentCheckData(AbstractPosAccount $posAccount, PosInterface::MODEL_3D_SECURE, $creditCard ); - $this->assertEquals($expectedData, $actual); + $this->assertSame($expectedData, $actual); } /** @@ -228,7 +237,6 @@ public static function registerDataProvider(): iterable 'AllowNotEnrolledCard' => 'false', 'SuccessUrl' => 'https://domain.com/success', 'FailUrl' => 'https://domain.com/fail_url', - 'HashedData' => 'apZ/1+eWzqCRk9qqACxN0bBZQ8g=', 'RequestLanguage' => 'tr-TR', 'Extract' => '', 'CustomItems' => '', @@ -238,6 +246,7 @@ public static function registerDataProvider(): iterable 'ExpireMonth' => '12', 'ExpireYear' => '21', 'CardHoldersName' => 'ahmet', + 'HashedData' => 'apZ/1+eWzqCRk9qqACxN0bBZQ8g=', ], ]; @@ -258,10 +267,10 @@ public static function registerDataProvider(): iterable 'AllowNotEnrolledCard' => 'false', 'SuccessUrl' => 'https://domain.com/success', 'FailUrl' => 'https://domain.com/fail_url', - 'HashedData' => 'apZ/1+eWzqCRk9qqACxN0bBZQ8g=', 'RequestLanguage' => 'tr-TR', 'Extract' => '', 'CustomItems' => '', + 'HashedData' => 'apZ/1+eWzqCRk9qqACxN0bBZQ8g=', ], ]; } diff --git a/tests/Unit/DataMapper/RequestDataMapper/PosNetRequestDataMapperTest.php b/tests/Unit/DataMapper/RequestDataMapper/PosNetRequestDataMapperTest.php index 889dead6..ebfe9653 100644 --- a/tests/Unit/DataMapper/RequestDataMapper/PosNetRequestDataMapperTest.php +++ b/tests/Unit/DataMapper/RequestDataMapper/PosNetRequestDataMapperTest.php @@ -6,19 +6,17 @@ namespace Mews\Pos\Tests\Unit\DataMapper\RequestDataMapper; use InvalidArgumentException; +use Mews\Pos\Crypt\CryptInterface; use Mews\Pos\DataMapper\RequestDataMapper\PosNetRequestDataMapper; use Mews\Pos\Entity\Account\PosNetAccount; use Mews\Pos\Entity\Card\CreditCardInterface; use Mews\Pos\Exceptions\UnsupportedTransactionTypeException; use Mews\Pos\Factory\AccountFactory; use Mews\Pos\Factory\CreditCardFactory; -use Mews\Pos\Factory\CryptFactory; -use Mews\Pos\Gateways\PosNet; use Mews\Pos\PosInterface; use PHPUnit\Framework\MockObject\MockObject; use PHPUnit\Framework\TestCase; use Psr\EventDispatcher\EventDispatcherInterface; -use Psr\Log\NullLogger; /** * @covers \Mews\Pos\DataMapper\RequestDataMapper\PosNetRequestDataMapper @@ -37,6 +35,9 @@ class PosNetRequestDataMapperTest extends TestCase /** @var EventDispatcherInterface & MockObject */ private EventDispatcherInterface $dispatcher; + /** @var CryptInterface & MockObject */ + private CryptInterface $crypt; + protected function setUp(): void { parent::setUp(); @@ -61,8 +62,8 @@ protected function setUp(): void ]; $this->dispatcher = $this->createMock(EventDispatcherInterface::class); - $crypt = CryptFactory::createGatewayCrypt(PosNet::class, new NullLogger()); - $this->requestDataMapper = new PosNetRequestDataMapper($this->dispatcher, $crypt); + $this->crypt = $this->createMock(CryptInterface::class); + $this->requestDataMapper = new PosNetRequestDataMapper($this->dispatcher, $this->crypt); $this->card = CreditCardFactory::create('5555444433332222', '22', '01', '123', 'ahmet'); } @@ -191,11 +192,16 @@ public function testCreateCancelRequestData(array $order, array $expectedData): /** * @dataProvider create3DPaymentRequestDataDataProvider */ - public function testCreate3DPaymentRequestData(array $order, string $txType, array $responseData, array $expected): void + public function testCreate3DPaymentRequestData(array $order, array $mappedOrder, string $txType, array $responseData, array $expected): void { + $this->crypt->expects(self::once()) + ->method('create3DHash') + ->with($this->account, $mappedOrder) + ->willReturn($expected['oosTranData']['mac']); + $actual = $this->requestDataMapper->create3DPaymentRequestData($this->account, $order, $txType, $responseData); - $this->assertEquals($expected, $actual); + $this->assertSame($expected, $actual); } /** @@ -221,11 +227,16 @@ public function testCreate3DEnrollmentCheckRequestDataFailTooLongOrderId(): void /** * @dataProvider resolveMerchantDataDataProvider */ - public function testCreate3DResolveMerchantRequestData(array $order, array $responseData, array $expectedData): void + public function testCreate3DResolveMerchantRequestData(array $order, array $mappedOrder, array $responseData, array $expectedData): void { + $this->crypt->expects(self::once()) + ->method('create3DHash') + ->with($this->account, $mappedOrder) + ->willReturn($expectedData['oosResolveMerchantData']['mac']); + $actualData = $this->requestDataMapper->create3DResolveMerchantRequestData($this->account, $order, $responseData); - $this->assertEquals($expectedData, $actualData); + $this->assertSame($expectedData, $actualData); } /** @@ -349,6 +360,12 @@ public static function create3DPaymentRequestDataDataProvider(): array 'installment' => '0', 'currency' => PosInterface::CURRENCY_TRY, ], + 'mapped_order' => [ + 'id' => '000000002020110828BC', + 'amount' => 10001, + 'installment' => '0', + 'currency' => 'TL', + ], 'txType' => PosInterface::TX_TYPE_PAY_AUTH, 'responseData' => [ 'BankPacket' => 'F61E1D0C0FB6EC5203A748124F309998F61E1D0C0FB6EC5203A748124F30', @@ -587,6 +604,12 @@ public static function resolveMerchantDataDataProvider(): array 'installment' => '0', 'currency' => PosInterface::CURRENCY_TRY, ], + 'mapped_order' => [ + 'id' => '000000002020110828BC', + 'amount' => 10001, + 'installment' => '0', + 'currency' => 'TL', + ], 'response_data' => [ 'BankPacket' => 'F61E1D0C0FB6EC5203A748124F309998F61E1D0C0FB6EC5203A748124F30', 'MerchantPacket' => 'E1D0C0FB6EC5203A748124F309998F61E1D0C0FB6EC5203A748124F309998F61E1D0C0FB6EC5203A748124F30', diff --git a/tests/Unit/DataMapper/RequestDataMapper/PosNetV1PosRequestDataMapperTest.php b/tests/Unit/DataMapper/RequestDataMapper/PosNetV1PosRequestDataMapperTest.php index 7c1bd702..39f952d3 100644 --- a/tests/Unit/DataMapper/RequestDataMapper/PosNetV1PosRequestDataMapperTest.php +++ b/tests/Unit/DataMapper/RequestDataMapper/PosNetV1PosRequestDataMapperTest.php @@ -6,6 +6,7 @@ namespace Mews\Pos\Tests\Unit\DataMapper\RequestDataMapper; use InvalidArgumentException; +use Mews\Pos\Crypt\CryptInterface; use Mews\Pos\DataMapper\RequestDataMapper\PosNetV1PosRequestDataMapper; use Mews\Pos\Entity\Account\PosNetAccount; use Mews\Pos\Entity\Card\CreditCardInterface; @@ -13,13 +14,11 @@ use Mews\Pos\Exceptions\UnsupportedTransactionTypeException; use Mews\Pos\Factory\AccountFactory; use Mews\Pos\Factory\CreditCardFactory; -use Mews\Pos\Factory\CryptFactory; use Mews\Pos\Gateways\PosNetV1Pos; use Mews\Pos\PosInterface; use PHPUnit\Framework\MockObject\MockObject; use PHPUnit\Framework\TestCase; use Psr\EventDispatcher\EventDispatcherInterface; -use Psr\Log\NullLogger; /** * @covers \Mews\Pos\DataMapper\RequestDataMapper\PosNetV1PosRequestDataMapper @@ -36,6 +35,9 @@ class PosNetV1PosRequestDataMapperTest extends TestCase /** @var EventDispatcherInterface & MockObject */ private EventDispatcherInterface $dispatcher; + /** @var CryptInterface & MockObject */ + private CryptInterface $crypt; + protected function setUp(): void { parent::setUp(); @@ -53,8 +55,8 @@ protected function setUp(): void $this->card = CreditCardFactory::create('5400619360964581', '20', '01', '056', 'ahmet'); - $crypt = CryptFactory::createGatewayCrypt(PosNetV1Pos::class, new NullLogger()); - $this->requestDataMapper = new PosNetV1PosRequestDataMapper($this->dispatcher, $crypt); + $this->crypt = $this->createMock(CryptInterface::class); + $this->requestDataMapper = new PosNetV1PosRequestDataMapper($this->dispatcher, $this->crypt); } /** @@ -154,9 +156,17 @@ public function testFormatOrderIdFail(): void */ public function testCreateNonSecurePostAuthPaymentRequestData(array $order, array $expectedData): void { + $hashCalculationData = $expectedData; + unset($hashCalculationData['MAC']); + + $this->crypt->expects(self::once()) + ->method('hashFromParams') + ->with($this->account->getStoreKey(), $hashCalculationData, 'MACParams', ':') + ->willReturn($expectedData['MAC']); + $actual = $this->requestDataMapper->createNonSecurePostAuthPaymentRequestData($this->account, $order); - $this->assertEquals($expectedData, $actual); + $this->assertSame($expectedData, $actual); } /** @@ -164,9 +174,17 @@ public function testCreateNonSecurePostAuthPaymentRequestData(array $order, arra */ public function testCreateNonSecurePaymentRequestData(array $order, array $expectedData): void { + $hashCalculationData = $expectedData; + unset($hashCalculationData['MAC']); + + $this->crypt->expects(self::once()) + ->method('hashFromParams') + ->with($this->account->getStoreKey(), $hashCalculationData, 'MACParams', ':') + ->willReturn($expectedData['MAC']); + $actual = $this->requestDataMapper->createNonSecurePaymentRequestData($this->account, $order, PosInterface::TX_TYPE_PAY_AUTH, $this->card); - $this->assertEquals($expectedData, $actual); + $this->assertSame($expectedData, $actual); } /** @@ -174,9 +192,17 @@ public function testCreateNonSecurePaymentRequestData(array $order, array $expec */ public function testCreate3DPaymentRequestData(array $order, string $txType, array $responseData, array $expectedData): void { + $hashCalculationData = $expectedData; + unset($hashCalculationData['MAC']); + + $this->crypt->expects(self::once()) + ->method('createHash') + ->with($this->account, $hashCalculationData) + ->willReturn($expectedData['MAC']); + $actual = $this->requestDataMapper->create3DPaymentRequestData($this->account, $order, $txType, $responseData); - $this->assertEquals($expectedData, $actual); + $this->assertSame($expectedData, $actual); } /** @@ -193,6 +219,14 @@ public function testCreate3DFormData(array $order, string $txType, string $gatew && $paymentModel === $dispatchedEvent->getPaymentModel() && count($dispatchedEvent->getFormInputs()) > 3)); + $hashCalculationData = $expected['inputs']; + unset($hashCalculationData['Mac']); + + $this->crypt->expects(self::once()) + ->method('create3DHash') + ->with($this->account, $hashCalculationData) + ->willReturn($expected['inputs']['Mac']); + $actual = $this->requestDataMapper->create3DFormData( $this->account, $order, @@ -210,8 +244,16 @@ public function testCreate3DFormData(array $order, string $txType, string $gatew */ public function testCreateStatusRequestData(array $order, array $expected): void { + $hashCalculationData = $expected; + unset($hashCalculationData['MAC']); + + $this->crypt->expects(self::once()) + ->method('hashFromParams') + ->with($this->account->getStoreKey(), $hashCalculationData, 'MACParams', ':') + ->willReturn($expected['MAC']); + $actual = $this->requestDataMapper->createStatusRequestData($this->account, $order); - $this->assertEquals($expected, $actual); + $this->assertSame($expected, $actual); } /** @@ -219,6 +261,14 @@ public function testCreateStatusRequestData(array $order, array $expected): void */ public function testCreateRefundRequestData(array $order, string $txType, array $expected): void { + $hashCalculationData = $expected; + unset($hashCalculationData['MAC']); + + $this->crypt->expects(self::once()) + ->method('hashFromParams') + ->with($this->account->getStoreKey(), $hashCalculationData, 'MACParams', ':') + ->willReturn($expected['MAC']); + $actual = $this->requestDataMapper->createRefundRequestData($this->account, $order, $txType); ksort($actual); @@ -232,8 +282,19 @@ public function testCreateRefundRequestData(array $order, string $txType, array */ public function testCreateCancelRequestData(array $order, array $expected): void { + $hashCalculationData = $expected; + unset($hashCalculationData['MAC']); + + $this->crypt->expects(self::once()) + ->method('hashFromParams') + ->with($this->account->getStoreKey(), $hashCalculationData, 'MACParams', ':') + ->willReturn($expected['MAC']); + $actual = $this->requestDataMapper->createCancelRequestData($this->account, $order); - $this->assertEquals($expected, $actual); + + ksort($actual); + ksort($expected); + $this->assertSame($expected, $actual); } public function testCreateHistoryRequestData(): void @@ -789,12 +850,12 @@ public static function createStatusRequestDataDataProvider(): iterable 'MerchantNo' => '6700950031', 'TerminalNo' => '67540050', 'MACParams' => 'MerchantNo:TerminalNo', - 'MAC' => 'wgyfAJPbEPtTtce/+HRlXajSRfYA0J6mUcH+16EbB78=', 'CipheredData' => null, 'DealerData' => null, 'IsEncrypted' => 'N', 'PaymentFacilitatorData' => null, 'OrderId' => 'TDS_000000002020110828BC', + 'MAC' => 'wgyfAJPbEPtTtce/+HRlXajSRfYA0J6mUcH+16EbB78=', ], ]; } diff --git a/tests/Unit/DataMapper/RequestDataMapper/VakifKatilimPosRequestDataMapperTest.php b/tests/Unit/DataMapper/RequestDataMapper/VakifKatilimPosRequestDataMapperTest.php index 1f4a7a8f..a558f77f 100644 --- a/tests/Unit/DataMapper/RequestDataMapper/VakifKatilimPosRequestDataMapperTest.php +++ b/tests/Unit/DataMapper/RequestDataMapper/VakifKatilimPosRequestDataMapperTest.php @@ -6,21 +6,20 @@ namespace Mews\Pos\Tests\Unit\DataMapper\RequestDataMapper; use Generator; +use Mews\Pos\Crypt\CryptInterface; use Mews\Pos\DataMapper\RequestDataMapper\VakifKatilimPosRequestDataMapper; use Mews\Pos\Entity\Account\KuveytPosAccount; use Mews\Pos\Entity\Card\CreditCardInterface; use Mews\Pos\Factory\AccountFactory; use Mews\Pos\Factory\CreditCardFactory; -use Mews\Pos\Factory\CryptFactory; -use Mews\Pos\Gateways\VakifKatilimPos; use Mews\Pos\PosInterface; use PHPUnit\Framework\MockObject\MockObject; use PHPUnit\Framework\TestCase; use Psr\EventDispatcher\EventDispatcherInterface; -use Psr\Log\NullLogger; /** * @covers \Mews\Pos\DataMapper\RequestDataMapper\VakifKatilimPosRequestDataMapper + * @covers \Mews\Pos\DataMapper\RequestDataMapper\AbstractRequestDataMapper */ class VakifKatilimPosRequestDataMapperTest extends TestCase { @@ -33,6 +32,9 @@ class VakifKatilimPosRequestDataMapperTest extends TestCase /** @var EventDispatcherInterface & MockObject */ private EventDispatcherInterface $dispatcher; + /** @var CryptInterface & MockObject */ + private CryptInterface $crypt; + protected function setUp(): void { parent::setUp(); @@ -45,8 +47,6 @@ protected function setUp(): void 'kdsnsksl', ); - $this->dispatcher = $this->createMock(EventDispatcherInterface::class); - $this->card = CreditCardFactory::create( '4155650100416111', 25, @@ -55,8 +55,9 @@ protected function setUp(): void 'John Doe', ); - $crypt = CryptFactory::createGatewayCrypt(VakifKatilimPos::class, new NullLogger()); - $this->requestDataMapper = new VakifKatilimPosRequestDataMapper($this->dispatcher, $crypt); + $this->dispatcher = $this->createMock(EventDispatcherInterface::class); + $this->crypt = $this->createMock(CryptInterface::class); + $this->requestDataMapper = new VakifKatilimPosRequestDataMapper($this->dispatcher, $this->crypt); } /** @@ -115,6 +116,16 @@ public function testGet3DFormData( array $expected ): void { + if (PosInterface::MODEL_3D_HOST === $paymentModel) { + $hashCalculationData = $expected['inputs']; + unset($hashCalculationData['HashPassword']); + + $this->crypt->expects(self::once()) + ->method('hashString') + ->with($this->account->getStoreKey()) + ->willReturn($expected['inputs']['HashPassword']); + } + $actual = $this->requestDataMapper->create3DFormData( $this->account, $order, @@ -123,7 +134,7 @@ public function testGet3DFormData( $gatewayURL, ); - $this->assertEquals($expected, $actual); + $this->assertSame($expected, $actual); } /** @@ -131,6 +142,19 @@ public function testGet3DFormData( */ public function testCreateNonSecurePaymentRequestData(array $order, array $expectedData): void { + $this->crypt->expects(self::once()) + ->method('hashString') + ->with($this->account->getStoreKey()) + ->willReturn($expectedData['HashPassword']); + + $hashCalculationData = $expectedData; + unset($hashCalculationData['HashData']); + + $this->crypt->expects(self::once()) + ->method('createHash') + ->with($this->account, $hashCalculationData) + ->willReturn($expectedData['HashData']); + $actual = $this->requestDataMapper->createNonSecurePaymentRequestData( $this->account, $order, @@ -138,7 +162,7 @@ public function testCreateNonSecurePaymentRequestData(array $order, array $expec $this->card ); - $this->assertEquals($expectedData, $actual); + $this->assertSame($expectedData, $actual); } /** @@ -146,12 +170,25 @@ public function testCreateNonSecurePaymentRequestData(array $order, array $expec */ public function testCreateNonSecurePostAuthPaymentRequestData(array $order, array $expectedData): void { + $this->crypt->expects(self::once()) + ->method('hashString') + ->with($this->account->getStoreKey()) + ->willReturn($expectedData['HashPassword']); + + $hashCalculationData = $expectedData; + unset($hashCalculationData['HashData']); + + $this->crypt->expects(self::once()) + ->method('createHash') + ->with($this->account, $hashCalculationData) + ->willReturn($expectedData['HashData']); + $actual = $this->requestDataMapper->createNonSecurePostAuthPaymentRequestData( $this->account, $order, ); - $this->assertEquals($expectedData, $actual); + $this->assertSame($expectedData, $actual); } @@ -163,6 +200,19 @@ public function testCreate3DEnrollmentCheckRequestData(array $order, string $txT $account = $this->account; $card = $this->card; + $this->crypt->expects(self::once()) + ->method('hashString') + ->with($account->getStoreKey()) + ->willReturn($expectedData['HashPassword']); + + $hashCalculationData = $expectedData; + unset($hashCalculationData['HashData']); + + $this->crypt->expects(self::once()) + ->method('create3DHash') + ->with($account, $hashCalculationData) + ->willReturn($expectedData['HashData']); + $actualData = $this->requestDataMapper->create3DEnrollmentCheckRequestData( $account, $order, @@ -181,8 +231,24 @@ public function testCreate3DEnrollmentCheckRequestData(array $order, string $txT */ public function testCreateCancelRequestData(array $order, array $expected): void { + $this->crypt->expects(self::once()) + ->method('hashString') + ->with($this->account->getStoreKey()) + ->willReturn($expected['HashPassword']); + + $hashCalculationData = $expected; + unset($hashCalculationData['HashData']); + + $this->crypt->expects(self::once()) + ->method('createHash') + ->with($this->account, $hashCalculationData) + ->willReturn($expected['HashData']); + $actual = $this->requestDataMapper->createCancelRequestData($this->account, $order); - $this->assertEquals($expected, $actual); + + ksort($actual); + ksort($expected); + $this->assertSame($expected, $actual); } /** @@ -190,6 +256,19 @@ public function testCreateCancelRequestData(array $order, array $expected): void */ public function testCreateRefundRequestData(array $order, string $txType, array $expected): void { + $this->crypt->expects(self::once()) + ->method('hashString') + ->with($this->account->getStoreKey()) + ->willReturn($expected['HashPassword']); + + $hashCalculationData = $expected; + unset($hashCalculationData['HashData']); + + $this->crypt->expects(self::once()) + ->method('createHash') + ->with($this->account, $hashCalculationData) + ->willReturn($expected['HashData']); + $actual = $this->requestDataMapper->createRefundRequestData($this->account, $order, $txType); \ksort($actual); @@ -202,8 +281,16 @@ public function testCreateRefundRequestData(array $order, string $txType, array */ public function testCreateHistoryRequestData(array $order, array $expected): void { + $hashCalculationData = $expected; + unset($hashCalculationData['HashData']); + + $this->crypt->expects(self::once()) + ->method('createHash') + ->with($this->account, $hashCalculationData) + ->willReturn($expected['HashData']); + $actual = $this->requestDataMapper->createHistoryRequestData($this->account, $order); - $this->assertEquals($expected, $actual); + $this->assertSame($expected, $actual); } @@ -212,8 +299,16 @@ public function testCreateHistoryRequestData(array $order, array $expected): voi */ public function testCreateOrderHistoryRequestData(array $order, array $expected): void { + $hashCalculationData = $expected; + unset($hashCalculationData['HashData']); + + $this->crypt->expects(self::once()) + ->method('createHash') + ->with($this->account, $hashCalculationData) + ->willReturn($expected['HashData']); + $actual = $this->requestDataMapper->createOrderHistoryRequestData($this->account, $order); - $this->assertEquals($expected, $actual); + $this->assertSame($expected, $actual); } /** @@ -221,8 +316,16 @@ public function testCreateOrderHistoryRequestData(array $order, array $expected) */ public function testCreateStatusRequestData(array $order, array $expected): void { + $hashCalculationData = $expected; + unset($hashCalculationData['HashData']); + + $this->crypt->expects(self::once()) + ->method('createHash') + ->with($this->account, $hashCalculationData) + ->willReturn($expected['HashData']); + $actual = $this->requestDataMapper->createStatusRequestData($this->account, $order); - $this->assertEquals($expected, $actual); + $this->assertSame($expected, $actual); } /** @@ -230,9 +333,19 @@ public function testCreateStatusRequestData(array $order, array $expected): void */ public function testCreate3DPaymentRequestData(KuveytPosAccount $kuveytPosAccount, array $order, string $txType, array $responseData, array $expectedData): void { + $hashCalculationData = $expectedData; + $hashCalculationData['HashData'] = ''; + + $this->crypt->expects(self::once()) + ->method('create3DHash') + ->with($kuveytPosAccount, $hashCalculationData) + ->willReturn($expectedData['HashData']); + $actual = $this->requestDataMapper->create3DPaymentRequestData($kuveytPosAccount, $order, $txType, $responseData); - $this->assertEquals($expectedData, $actual); + ksort($expectedData); + ksort($actual); + $this->assertSame($expectedData, $actual); } @@ -333,8 +446,8 @@ public static function createStatusRequestDataProvider(): iterable 'CustomerId' => '11111', 'UserName' => 'APIUSER', 'SubMerchantId' => '0', - 'HashData' => '4oNmzFPMeC/tOK8i/XCPNy4W+FU=', 'MerchantOrderId' => 'order-123', + 'HashData' => '4oNmzFPMeC/tOK8i/XCPNy4W+FU=', ], ]; } @@ -459,11 +572,11 @@ public static function nonSecurePaymentRequestDataDataProvider(): iterable 'FECCurrencyCode' => '0949', 'CurrencyCode' => '0949', 'TransactionSecurity' => '5', - 'CardHolderName' => 'John Doe', 'CardNumber' => '4155650100416111', 'CardExpireDateYear' => '25', 'CardExpireDateMonth' => '01', 'CardCVV2' => '123', + 'CardHolderName' => 'John Doe', 'HashData' => 'AYOjSzXn6dgwiV3U0vXzNTWlO8g=', ], ]; @@ -489,11 +602,11 @@ public static function nonSecurePaymentRequestDataDataProvider(): iterable 'CurrencyCode' => '0949', //'PaymentType' => '1', 'TransactionSecurity' => '5', - 'CardHolderName' => 'John Doe', 'CardNumber' => '4155650100416111', 'CardExpireDateYear' => '25', 'CardExpireDateMonth' => '01', 'CardCVV2' => '123', + 'CardHolderName' => 'John Doe', 'HashData' => 'AYOjSzXn6dgwiV3U0vXzNTWlO8g=', ], ]; @@ -514,9 +627,9 @@ public static function createNonSecurePostAuthPaymentRequestDataDataProvider(): 'SubMerchantId' => '0', 'HashPassword' => 'h58bUB83xQz2/21SUeOemUgkF5U=', 'MerchantOrderId' => '123', - 'HashData' => 'K0LvOf07C/ayD53wWiykcUCZPc8=', 'OrderId' => 'remote-123', 'CustomerIPAddress' => '127.0.0.1', + 'HashData' => 'K0LvOf07C/ayD53wWiykcUCZPc8=', ], ]; } @@ -535,7 +648,6 @@ public static function createHistoryRequestDataProvider(): Generator 'CustomerId' => '11111', 'UserName' => 'APIUSER', 'SubMerchantId' => '0', - 'HashData' => '58xhdJGlgIZtsid8cvSDlr8EItk=', 'StartDate' => '2024-03-30', 'EndDate' => '2024-03-31', 'LowerLimit' => 0, @@ -544,6 +656,7 @@ public static function createHistoryRequestDataProvider(): Generator 'OrderStatus' => null, 'TranResult' => null, 'OrderNo' => null, + 'HashData' => '58xhdJGlgIZtsid8cvSDlr8EItk=', ], ]; } @@ -561,7 +674,6 @@ public static function createOrderHistoryRequestDataProvider(): Generator 'CustomerId' => '11111', 'UserName' => 'APIUSER', 'SubMerchantId' => '0', - 'HashData' => '58xhdJGlgIZtsid8cvSDlr8EItk=', 'StartDate' => '2024-03-30', 'EndDate' => '2024-03-31', 'LowerLimit' => 0, @@ -570,6 +682,7 @@ public static function createOrderHistoryRequestDataProvider(): Generator 'OrderStatus' => null, 'TranResult' => null, 'OrderNo' => null, + 'HashData' => '58xhdJGlgIZtsid8cvSDlr8EItk=', ], ]; } diff --git a/tests/Unit/DataMapper/ResponseDataMapper/AkbankPosResponseDataMapperTest.php b/tests/Unit/DataMapper/ResponseDataMapper/AkbankPosResponseDataMapperTest.php index e2500e50..f0f22df9 100644 --- a/tests/Unit/DataMapper/ResponseDataMapper/AkbankPosResponseDataMapperTest.php +++ b/tests/Unit/DataMapper/ResponseDataMapper/AkbankPosResponseDataMapperTest.php @@ -9,9 +9,10 @@ use Mews\Pos\DataMapper\RequestDataMapper\AkbankPosRequestDataMapper; use Mews\Pos\DataMapper\ResponseDataMapper\AkbankPosResponseDataMapper; use Mews\Pos\PosInterface; +use PHPUnit\Framework\MockObject\MockObject; use PHPUnit\Framework\TestCase; use Psr\EventDispatcher\EventDispatcherInterface; -use Psr\Log\NullLogger; +use Psr\Log\LoggerInterface; /** * @covers \Mews\Pos\DataMapper\ResponseDataMapper\AkbankPosResponseDataMapper @@ -21,10 +22,15 @@ class AkbankPosResponseDataMapperTest extends TestCase { private AkbankPosResponseDataMapper $responseDataMapper; + /** @var LoggerInterface&MockObject */ + private LoggerInterface $logger; + protected function setUp(): void { parent::setUp(); + $this->logger = $this->createMock(LoggerInterface::class); + $requestDataMapper = new AkbankPosRequestDataMapper( $this->createMock(EventDispatcherInterface::class), $this->createMock(CryptInterface::class), @@ -34,7 +40,7 @@ protected function setUp(): void $requestDataMapper->getCurrencyMappings(), $requestDataMapper->getTxTypeMappings(), $requestDataMapper->getSecureTypeMappings(), - new NullLogger() + $this->logger ); } diff --git a/tests/Unit/DataMapper/ResponseDataMapper/EstPosResponseDataMapperTest.php b/tests/Unit/DataMapper/ResponseDataMapper/EstPosResponseDataMapperTest.php index c75c6ce8..5be978b7 100644 --- a/tests/Unit/DataMapper/ResponseDataMapper/EstPosResponseDataMapperTest.php +++ b/tests/Unit/DataMapper/ResponseDataMapper/EstPosResponseDataMapperTest.php @@ -5,34 +5,42 @@ namespace Mews\Pos\Tests\Unit\DataMapper\ResponseDataMapper; +use Mews\Pos\Crypt\CryptInterface; use Mews\Pos\DataMapper\RequestDataMapper\EstPosRequestDataMapper; use Mews\Pos\DataMapper\ResponseDataMapper\EstPosResponseDataMapper; -use Mews\Pos\Factory\CryptFactory; -use Mews\Pos\Gateways\EstPos; use Mews\Pos\PosInterface; +use PHPUnit\Framework\MockObject\MockObject; use PHPUnit\Framework\TestCase; use Psr\EventDispatcher\EventDispatcherInterface; -use Psr\Log\NullLogger; +use Psr\Log\LoggerInterface; /** * @covers \Mews\Pos\DataMapper\ResponseDataMapper\EstPosResponseDataMapper + * @covers \Mews\Pos\DataMapper\ResponseDataMapper\AbstractResponseDataMapper */ class EstPosResponseDataMapperTest extends TestCase { private EstPosResponseDataMapper $responseDataMapper; + /** @var LoggerInterface&MockObject */ + private LoggerInterface $logger; + protected function setUp(): void { parent::setUp(); - $crypt = CryptFactory::createGatewayCrypt(EstPos::class, new NullLogger()); - $requestDataMapper = new EstPosRequestDataMapper($this->createMock(EventDispatcherInterface::class), $crypt); + $this->logger = $this->createMock(LoggerInterface::class); + + $requestDataMapper = new EstPosRequestDataMapper( + $this->createMock(EventDispatcherInterface::class), + $this->createMock(CryptInterface::class), + ); $this->responseDataMapper = new EstPosResponseDataMapper( $requestDataMapper->getCurrencyMappings(), $requestDataMapper->getTxTypeMappings(), $requestDataMapper->getSecureTypeMappings(), - new NullLogger() + $this->logger, ); } diff --git a/tests/Unit/DataMapper/ResponseDataMapper/GarantiPosResponseDataMapperTest.php b/tests/Unit/DataMapper/ResponseDataMapper/GarantiPosResponseDataMapperTest.php index 5589809b..09b42c06 100644 --- a/tests/Unit/DataMapper/ResponseDataMapper/GarantiPosResponseDataMapperTest.php +++ b/tests/Unit/DataMapper/ResponseDataMapper/GarantiPosResponseDataMapperTest.php @@ -5,15 +5,15 @@ namespace Mews\Pos\Tests\Unit\DataMapper\ResponseDataMapper; +use Mews\Pos\Crypt\CryptInterface; use Mews\Pos\DataMapper\RequestDataMapper\GarantiPosRequestDataMapper; use Mews\Pos\DataMapper\ResponseDataMapper\GarantiPosResponseDataMapper; use Mews\Pos\Exceptions\NotImplementedException; -use Mews\Pos\Factory\CryptFactory; -use Mews\Pos\Gateways\GarantiPos; use Mews\Pos\PosInterface; +use PHPUnit\Framework\MockObject\MockObject; use PHPUnit\Framework\TestCase; use Psr\EventDispatcher\EventDispatcherInterface; -use Psr\Log\NullLogger; +use Psr\Log\LoggerInterface; /** * @covers \Mews\Pos\DataMapper\ResponseDataMapper\GarantiPosResponseDataMapper @@ -23,17 +23,25 @@ class GarantiPosResponseDataMapperTest extends TestCase { private GarantiPosResponseDataMapper $responseDataMapper; + /** @var LoggerInterface&MockObject */ + private LoggerInterface $logger; + protected function setUp(): void { parent::setUp(); - $crypt = CryptFactory::createGatewayCrypt(GarantiPos::class, new NullLogger()); - $requestDataMapper = new GarantiPosRequestDataMapper($this->createMock(EventDispatcherInterface::class), $crypt); + $this->logger = $this->createMock(LoggerInterface::class); + + $requestDataMapper = new GarantiPosRequestDataMapper( + $this->createMock(EventDispatcherInterface::class), + $this->createMock(CryptInterface::class), + ); + $this->responseDataMapper = new GarantiPosResponseDataMapper( $requestDataMapper->getCurrencyMappings(), $requestDataMapper->getTxTypeMappings(), $requestDataMapper->getSecureTypeMappings(), - new NullLogger() + $this->logger, ); } diff --git a/tests/Unit/DataMapper/ResponseDataMapper/InterPosResponseDataMapperTest.php b/tests/Unit/DataMapper/ResponseDataMapper/InterPosResponseDataMapperTest.php index e5b66544..5516cf02 100644 --- a/tests/Unit/DataMapper/ResponseDataMapper/InterPosResponseDataMapperTest.php +++ b/tests/Unit/DataMapper/ResponseDataMapper/InterPosResponseDataMapperTest.php @@ -5,34 +5,43 @@ namespace Mews\Pos\Tests\Unit\DataMapper\ResponseDataMapper; +use Mews\Pos\Crypt\CryptInterface; use Mews\Pos\DataMapper\RequestDataMapper\InterPosRequestDataMapper; use Mews\Pos\DataMapper\ResponseDataMapper\InterPosResponseDataMapper; use Mews\Pos\Exceptions\NotImplementedException; -use Mews\Pos\Factory\CryptFactory; -use Mews\Pos\Gateways\InterPos; use Mews\Pos\PosInterface; +use PHPUnit\Framework\MockObject\MockObject; use PHPUnit\Framework\TestCase; use Psr\EventDispatcher\EventDispatcherInterface; -use Psr\Log\NullLogger; +use Psr\Log\LoggerInterface; /** * @covers \Mews\Pos\DataMapper\ResponseDataMapper\InterPosResponseDataMapper + * @covers \Mews\Pos\DataMapper\ResponseDataMapper\AbstractResponseDataMapper */ class InterPosResponseDataMapperTest extends TestCase { private InterPosResponseDataMapper $responseDataMapper; + /** @var LoggerInterface&MockObject */ + private LoggerInterface $logger; + protected function setUp(): void { parent::setUp(); - $crypt = CryptFactory::createGatewayCrypt(InterPos::class, new NullLogger()); - $requestDataMapper = new InterPosRequestDataMapper($this->createMock(EventDispatcherInterface::class), $crypt); + $this->logger = $this->createMock(LoggerInterface::class); + + $requestDataMapper = new InterPosRequestDataMapper( + $this->createMock(EventDispatcherInterface::class), + $this->createMock(CryptInterface::class), + ); + $this->responseDataMapper = new InterPosResponseDataMapper( $requestDataMapper->getCurrencyMappings(), $requestDataMapper->getTxTypeMappings(), $requestDataMapper->getSecureTypeMappings(), - new NullLogger() + $this->logger, ); } diff --git a/tests/Unit/DataMapper/ResponseDataMapper/KuveytPosResponseDataMapperTest.php b/tests/Unit/DataMapper/ResponseDataMapper/KuveytPosResponseDataMapperTest.php index 15d7e926..31480e48 100644 --- a/tests/Unit/DataMapper/ResponseDataMapper/KuveytPosResponseDataMapperTest.php +++ b/tests/Unit/DataMapper/ResponseDataMapper/KuveytPosResponseDataMapperTest.php @@ -5,15 +5,15 @@ namespace Mews\Pos\Tests\Unit\DataMapper\ResponseDataMapper; +use Mews\Pos\Crypt\CryptInterface; use Mews\Pos\DataMapper\RequestDataMapper\KuveytPosRequestDataMapper; use Mews\Pos\DataMapper\ResponseDataMapper\KuveytPosResponseDataMapper; use Mews\Pos\Exceptions\NotImplementedException; -use Mews\Pos\Factory\CryptFactory; -use Mews\Pos\Gateways\KuveytPos; use Mews\Pos\PosInterface; +use PHPUnit\Framework\MockObject\MockObject; use PHPUnit\Framework\TestCase; use Psr\EventDispatcher\EventDispatcherInterface; -use Psr\Log\NullLogger; +use Psr\Log\LoggerInterface; /** * @covers \Mews\Pos\DataMapper\ResponseDataMapper\KuveytPosResponseDataMapper @@ -23,17 +23,24 @@ class KuveytPosResponseDataMapperTest extends TestCase { private KuveytPosResponseDataMapper $responseDataMapper; + /** @var LoggerInterface&MockObject */ + private LoggerInterface $logger; + protected function setUp(): void { parent::setUp(); - $crypt = CryptFactory::createGatewayCrypt(KuveytPos::class, new NullLogger()); - $requestDataMapper = new KuveytPosRequestDataMapper($this->createMock(EventDispatcherInterface::class), $crypt); + $this->logger = $this->createMock(LoggerInterface::class); + + $requestDataMapper = new KuveytPosRequestDataMapper( + $this->createMock(EventDispatcherInterface::class), + $this->createMock(CryptInterface::class), + ); $this->responseDataMapper = new KuveytPosResponseDataMapper( $requestDataMapper->getCurrencyMappings(), $requestDataMapper->getTxTypeMappings(), $requestDataMapper->getSecureTypeMappings(), - new NullLogger() + $this->logger, ); } diff --git a/tests/Unit/DataMapper/ResponseDataMapper/PayFlexCPV4PosResponseDataMapperTest.php b/tests/Unit/DataMapper/ResponseDataMapper/PayFlexCPV4PosResponseDataMapperTest.php index 1dc0cc0f..785933a5 100644 --- a/tests/Unit/DataMapper/ResponseDataMapper/PayFlexCPV4PosResponseDataMapperTest.php +++ b/tests/Unit/DataMapper/ResponseDataMapper/PayFlexCPV4PosResponseDataMapperTest.php @@ -6,33 +6,41 @@ namespace Mews\Pos\Tests\Unit\DataMapper\ResponseDataMapper; use Generator; +use Mews\Pos\Crypt\CryptInterface; use Mews\Pos\DataMapper\RequestDataMapper\PayFlexCPV4PosRequestDataMapper; use Mews\Pos\DataMapper\ResponseDataMapper\PayFlexCPV4PosResponseDataMapper; -use Mews\Pos\Factory\CryptFactory; -use Mews\Pos\Gateways\PayFlexCPV4Pos; use Mews\Pos\PosInterface; +use PHPUnit\Framework\MockObject\MockObject; use PHPUnit\Framework\TestCase; use Psr\EventDispatcher\EventDispatcherInterface; -use Psr\Log\NullLogger; +use Psr\Log\LoggerInterface; /** * @covers \Mews\Pos\DataMapper\ResponseDataMapper\PayFlexCPV4PosResponseDataMapper + * @covers \Mews\Pos\DataMapper\ResponseDataMapper\AbstractResponseDataMapper */ class PayFlexCPV4PosResponseDataMapperTest extends TestCase { private PayFlexCPV4PosResponseDataMapper $responseDataMapper; + /** @var LoggerInterface&MockObject */ + private LoggerInterface $logger; + protected function setUp(): void { parent::setUp(); - $crypt = CryptFactory::createGatewayCrypt(PayFlexCPV4Pos::class, new NullLogger()); - $requestDataMapper = new PayFlexCPV4PosRequestDataMapper($this->createMock(EventDispatcherInterface::class), $crypt); + $this->logger = $this->createMock(LoggerInterface::class); + + $requestDataMapper = new PayFlexCPV4PosRequestDataMapper( + $this->createMock(EventDispatcherInterface::class), + $this->createMock(CryptInterface::class), + ); $this->responseDataMapper = new PayFlexCPV4PosResponseDataMapper( $requestDataMapper->getCurrencyMappings(), $requestDataMapper->getTxTypeMappings(), $requestDataMapper->getSecureTypeMappings(), - new NullLogger() + $this->logger, ); } diff --git a/tests/Unit/DataMapper/ResponseDataMapper/PayFlexV4PosResponseDataMapperTest.php b/tests/Unit/DataMapper/ResponseDataMapper/PayFlexV4PosResponseDataMapperTest.php index 9396002e..ec6ed1a1 100644 --- a/tests/Unit/DataMapper/ResponseDataMapper/PayFlexV4PosResponseDataMapperTest.php +++ b/tests/Unit/DataMapper/ResponseDataMapper/PayFlexV4PosResponseDataMapperTest.php @@ -10,9 +10,10 @@ use Mews\Pos\DataMapper\ResponseDataMapper\PayFlexV4PosResponseDataMapper; use Mews\Pos\Exceptions\NotImplementedException; use Mews\Pos\PosInterface; +use PHPUnit\Framework\MockObject\MockObject; use PHPUnit\Framework\TestCase; use Psr\EventDispatcher\EventDispatcherInterface; -use Psr\Log\NullLogger; +use Psr\Log\LoggerInterface; /** * @covers \Mews\Pos\DataMapper\ResponseDataMapper\PayFlexV4PosResponseDataMapper @@ -22,10 +23,15 @@ class PayFlexV4PosResponseDataMapperTest extends TestCase { private PayFlexV4PosResponseDataMapper $responseDataMapper; + /** @var LoggerInterface&MockObject */ + private LoggerInterface $logger; + protected function setUp(): void { parent::setUp(); + $this->logger = $this->createMock(LoggerInterface::class); + $requestDataMapper = new PayFlexV4PosRequestDataMapper( $this->createMock(EventDispatcherInterface::class), $this->createMock(CryptInterface::class) @@ -34,7 +40,7 @@ protected function setUp(): void $requestDataMapper->getCurrencyMappings(), $requestDataMapper->getTxTypeMappings(), $requestDataMapper->getSecureTypeMappings(), - new NullLogger() + $this->logger, ); } diff --git a/tests/Unit/DataMapper/ResponseDataMapper/PayForPosResponseDataMapperTest.php b/tests/Unit/DataMapper/ResponseDataMapper/PayForPosResponseDataMapperTest.php index 6a62031d..97559120 100644 --- a/tests/Unit/DataMapper/ResponseDataMapper/PayForPosResponseDataMapperTest.php +++ b/tests/Unit/DataMapper/ResponseDataMapper/PayForPosResponseDataMapperTest.php @@ -5,31 +5,41 @@ namespace Mews\Pos\Tests\Unit\DataMapper\ResponseDataMapper; +use Mews\Pos\Crypt\CryptInterface; use Mews\Pos\Crypt\PayForPosCrypt; use Mews\Pos\DataMapper\RequestDataMapper\PayForPosRequestDataMapper; use Mews\Pos\DataMapper\ResponseDataMapper\PayForPosResponseDataMapper; use Mews\Pos\PosInterface; +use PHPUnit\Framework\MockObject\MockObject; use PHPUnit\Framework\TestCase; use Psr\EventDispatcher\EventDispatcherInterface; -use Psr\Log\NullLogger; +use Psr\Log\LoggerInterface; /** * @covers \Mews\Pos\DataMapper\ResponseDataMapper\PayForPosResponseDataMapper + * @covers \Mews\Pos\DataMapper\ResponseDataMapper\AbstractResponseDataMapper */ class PayForPosResponseDataMapperTest extends TestCase { private PayForPosResponseDataMapper $responseDataMapper; + /** @var LoggerInterface&MockObject */ + private LoggerInterface $logger; + protected function setUp(): void { parent::setUp(); + $this->logger = $this->createMock(LoggerInterface::class); - $requestDataMapper = new PayForPosRequestDataMapper($this->createMock(EventDispatcherInterface::class), new PayForPosCrypt(new NullLogger())); + $requestDataMapper = new PayForPosRequestDataMapper( + $this->createMock(EventDispatcherInterface::class), + $this->createMock(CryptInterface::class), + ); $this->responseDataMapper = new PayForPosResponseDataMapper( $requestDataMapper->getCurrencyMappings(), $requestDataMapper->getTxTypeMappings(), $requestDataMapper->getSecureTypeMappings(), - new NullLogger() + $this->logger, ); } diff --git a/tests/Unit/DataMapper/ResponseDataMapper/PosNetResponseDataMapperTest.php b/tests/Unit/DataMapper/ResponseDataMapper/PosNetResponseDataMapperTest.php index 8dbbd31e..4d6e4cf7 100644 --- a/tests/Unit/DataMapper/ResponseDataMapper/PosNetResponseDataMapperTest.php +++ b/tests/Unit/DataMapper/ResponseDataMapper/PosNetResponseDataMapperTest.php @@ -5,34 +5,41 @@ namespace Mews\Pos\Tests\Unit\DataMapper\ResponseDataMapper; +use Mews\Pos\Crypt\CryptInterface; use Mews\Pos\DataMapper\RequestDataMapper\PosNetRequestDataMapper; use Mews\Pos\DataMapper\ResponseDataMapper\PosNetResponseDataMapper; use Mews\Pos\Exceptions\NotImplementedException; -use Mews\Pos\Factory\CryptFactory; -use Mews\Pos\Gateways\PosNet; use Mews\Pos\PosInterface; +use PHPUnit\Framework\MockObject\MockObject; use PHPUnit\Framework\TestCase; use Psr\EventDispatcher\EventDispatcherInterface; -use Psr\Log\NullLogger; +use Psr\Log\LoggerInterface; /** * @covers \Mews\Pos\DataMapper\ResponseDataMapper\PosNetResponseDataMapper + * @covers \Mews\Pos\DataMapper\ResponseDataMapper\AbstractResponseDataMapper */ class PosNetResponseDataMapperTest extends TestCase { private PosNetResponseDataMapper $responseDataMapper; + /** @var LoggerInterface&MockObject */ + private LoggerInterface $logger; + protected function setUp(): void { parent::setUp(); + $this->logger = $this->createMock(LoggerInterface::class); - $crypt = CryptFactory::createGatewayCrypt(PosNet::class, new NullLogger()); - $requestDataMapper = new PosNetRequestDataMapper($this->createMock(EventDispatcherInterface::class), $crypt); + $requestDataMapper = new PosNetRequestDataMapper( + $this->createMock(EventDispatcherInterface::class), + $this->createMock(CryptInterface::class), + ); $this->responseDataMapper = new PosNetResponseDataMapper( $requestDataMapper->getCurrencyMappings(), $requestDataMapper->getTxTypeMappings(), $requestDataMapper->getSecureTypeMappings(), - new NullLogger() + $this->logger, ); } diff --git a/tests/Unit/DataMapper/ResponseDataMapper/PosNetV1PosResponseDataMapperTest.php b/tests/Unit/DataMapper/ResponseDataMapper/PosNetV1PosResponseDataMapperTest.php index 164368c3..2377133b 100644 --- a/tests/Unit/DataMapper/ResponseDataMapper/PosNetV1PosResponseDataMapperTest.php +++ b/tests/Unit/DataMapper/ResponseDataMapper/PosNetV1PosResponseDataMapperTest.php @@ -5,34 +5,43 @@ namespace Mews\Pos\Tests\Unit\DataMapper\ResponseDataMapper; +use Mews\Pos\Crypt\CryptInterface; use Mews\Pos\DataMapper\RequestDataMapper\PosNetV1PosRequestDataMapper; use Mews\Pos\DataMapper\ResponseDataMapper\PosNetV1PosResponseDataMapper; use Mews\Pos\Exceptions\NotImplementedException; -use Mews\Pos\Factory\CryptFactory; -use Mews\Pos\Gateways\PosNetV1Pos; use Mews\Pos\PosInterface; +use PHPUnit\Framework\MockObject\MockObject; use PHPUnit\Framework\TestCase; use Psr\EventDispatcher\EventDispatcherInterface; -use Psr\Log\NullLogger; +use Psr\Log\LoggerInterface; /** * @covers \Mews\Pos\DataMapper\ResponseDataMapper\PosNetV1PosResponseDataMapper + * @covers \Mews\Pos\DataMapper\ResponseDataMapper\AbstractResponseDataMapper */ class PosNetV1PosResponseDataMapperTest extends TestCase { private PosNetV1PosResponseDataMapper $responseDataMapper; + /** @var LoggerInterface&MockObject */ + private LoggerInterface $logger; + protected function setUp(): void { parent::setUp(); - $crypt = CryptFactory::createGatewayCrypt(PosNetV1Pos::class, new NullLogger()); - $requestDataMapper = new PosNetV1PosRequestDataMapper($this->createMock(EventDispatcherInterface::class), $crypt); + + $this->logger = $this->createMock(LoggerInterface::class); + + $requestDataMapper = new PosNetV1PosRequestDataMapper( + $this->createMock(EventDispatcherInterface::class), + $this->createMock(CryptInterface::class), + ); $this->responseDataMapper = new PosNetV1PosResponseDataMapper( $requestDataMapper->getCurrencyMappings(), $requestDataMapper->getTxTypeMappings(), $requestDataMapper->getSecureTypeMappings(), - new NullLogger() + $this->logger, ); } diff --git a/tests/Unit/DataMapper/ResponseDataMapper/ToslaPosResponseDataMapperTest.php b/tests/Unit/DataMapper/ResponseDataMapper/ToslaPosResponseDataMapperTest.php index 37809300..b3531111 100644 --- a/tests/Unit/DataMapper/ResponseDataMapper/ToslaPosResponseDataMapperTest.php +++ b/tests/Unit/DataMapper/ResponseDataMapper/ToslaPosResponseDataMapperTest.php @@ -5,35 +5,43 @@ namespace Mews\Pos\Tests\Unit\DataMapper\ResponseDataMapper; +use Mews\Pos\Crypt\CryptInterface; use Mews\Pos\DataMapper\RequestDataMapper\ToslaPosRequestDataMapper; use Mews\Pos\DataMapper\ResponseDataMapper\ToslaPosResponseDataMapper; use Mews\Pos\Exceptions\NotImplementedException; -use Mews\Pos\Factory\CryptFactory; -use Mews\Pos\Gateways\ToslaPos; use Mews\Pos\PosInterface; +use PHPUnit\Framework\MockObject\MockObject; use PHPUnit\Framework\TestCase; use Psr\EventDispatcher\EventDispatcherInterface; -use Psr\Log\NullLogger; +use Psr\Log\LoggerInterface; /** * @covers \Mews\Pos\DataMapper\ResponseDataMapper\ToslaPosResponseDataMapper + * @covers \Mews\Pos\DataMapper\ResponseDataMapper\AbstractResponseDataMapper */ class ToslaPosResponseDataMapperTest extends TestCase { private ToslaPosResponseDataMapper $responseDataMapper; + /** @var LoggerInterface&MockObject */ + private LoggerInterface $logger; + protected function setUp(): void { parent::setUp(); - $crypt = CryptFactory::createGatewayCrypt(ToslaPos::class, new NullLogger()); - $requestDataMapper = new ToslaPosRequestDataMapper($this->createMock(EventDispatcherInterface::class), $crypt); + $this->logger = $this->createMock(LoggerInterface::class); + + $requestDataMapper = new ToslaPosRequestDataMapper( + $this->createMock(EventDispatcherInterface::class), + $this->createMock(CryptInterface::class), + ); $this->responseDataMapper = new ToslaPosResponseDataMapper( $requestDataMapper->getCurrencyMappings(), $requestDataMapper->getTxTypeMappings(), $requestDataMapper->getSecureTypeMappings(), - new NullLogger() + $this->logger, ); } diff --git a/tests/Unit/DataMapper/ResponseDataMapper/VakifKatilimPosResponseDataMapperTest.php b/tests/Unit/DataMapper/ResponseDataMapper/VakifKatilimPosResponseDataMapperTest.php index e748dff6..93c4a6d3 100644 --- a/tests/Unit/DataMapper/ResponseDataMapper/VakifKatilimPosResponseDataMapperTest.php +++ b/tests/Unit/DataMapper/ResponseDataMapper/VakifKatilimPosResponseDataMapperTest.php @@ -5,15 +5,15 @@ namespace Mews\Pos\Tests\Unit\DataMapper\ResponseDataMapper; +use Mews\Pos\Crypt\CryptInterface; use Mews\Pos\DataMapper\RequestDataMapper\VakifKatilimPosRequestDataMapper; use Mews\Pos\DataMapper\ResponseDataMapper\VakifKatilimPosResponseDataMapper; use Mews\Pos\Exceptions\NotImplementedException; -use Mews\Pos\Factory\CryptFactory; -use Mews\Pos\Gateways\VakifKatilimPos; use Mews\Pos\PosInterface; +use PHPUnit\Framework\MockObject\MockObject; use PHPUnit\Framework\TestCase; use Psr\EventDispatcher\EventDispatcherInterface; -use Psr\Log\NullLogger; +use Psr\Log\LoggerInterface; /** * @covers \Mews\Pos\DataMapper\ResponseDataMapper\VakifKatilimPosResponseDataMapper @@ -23,17 +23,23 @@ class VakifKatilimPosResponseDataMapperTest extends TestCase { private VakifKatilimPosResponseDataMapper $responseDataMapper; + /** @var LoggerInterface&MockObject */ + private LoggerInterface $logger; + protected function setUp(): void { parent::setUp(); + $this->logger = $this->createMock(LoggerInterface::class); - $crypt = CryptFactory::createGatewayCrypt(VakifKatilimPos::class, new NullLogger()); - $requestDataMapper = new VakifKatilimPosRequestDataMapper($this->createMock(EventDispatcherInterface::class), $crypt); + $requestDataMapper = new VakifKatilimPosRequestDataMapper( + $this->createMock(EventDispatcherInterface::class), + $this->createMock(CryptInterface::class), + ); $this->responseDataMapper = new VakifKatilimPosResponseDataMapper( $requestDataMapper->getCurrencyMappings(), $requestDataMapper->getTxTypeMappings(), $requestDataMapper->getSecureTypeMappings(), - new NullLogger() + $this->logger, ); }