diff --git a/tests/Unit/DataMapper/RequestDataMapper/InterPosRequestDataMapperTest.php b/tests/Unit/DataMapper/RequestDataMapper/InterPosRequestDataMapperTest.php index d6529a59..76d20879 100644 --- a/tests/Unit/DataMapper/RequestDataMapper/InterPosRequestDataMapperTest.php +++ b/tests/Unit/DataMapper/RequestDataMapper/InterPosRequestDataMapperTest.php @@ -125,13 +125,13 @@ public function testCreateNonSecurePostAuthPaymentRequestData(array $order, arra /** * @dataProvider createNonSecurePaymentRequestDataDataProvider */ - public function testCreateNonSecurePaymentRequestData(array $order, CreditCardInterface $card, array $expected): void + public function testCreateNonSecurePaymentRequestData(array $order, CreditCardInterface $creditCard, array $expected): void { $actual = $this->requestDataMapper->createNonSecurePaymentRequestData( $this->account, $order, PosInterface::TX_TYPE_PAY_AUTH, - $card + $creditCard ); $this->assertSame($expected, $actual); diff --git a/tests/Unit/DataMapper/RequestDataMapper/PayFlexV4PosRequestDataMapperTest.php b/tests/Unit/DataMapper/RequestDataMapper/PayFlexV4PosRequestDataMapperTest.php index dfe56a2d..df96798a 100644 --- a/tests/Unit/DataMapper/RequestDataMapper/PayFlexV4PosRequestDataMapperTest.php +++ b/tests/Unit/DataMapper/RequestDataMapper/PayFlexV4PosRequestDataMapperTest.php @@ -21,13 +21,12 @@ /** * @covers \Mews\Pos\DataMapper\RequestDataMapper\PayFlexV4PosRequestDataMapper + * @covers \Mews\Pos\DataMapper\RequestDataMapper\AbstractRequestDataMapper */ class PayFlexV4PosRequestDataMapperTest extends TestCase { public PayFlexAccount $account; - private CreditCardInterface $card; - private PayFlexV4PosRequestDataMapper $requestDataMapper; /** @var CryptInterface & MockObject */ @@ -36,8 +35,6 @@ class PayFlexV4PosRequestDataMapperTest extends TestCase /** @var EventDispatcherInterface & MockObject */ private EventDispatcherInterface $dispatcher; - private array $order; - protected function setUp(): void { parent::setUp(); @@ -50,22 +47,9 @@ protected function setUp(): void PosInterface::MODEL_3D_SECURE ); - - $this->order = [ - 'id' => 'order222', - 'amount' => 100.00, - 'installment' => 0, - 'currency' => PosInterface::CURRENCY_TRY, - 'success_url' => 'https://domain.com/success', - 'fail_url' => 'https://domain.com/fail_url', - 'ip' => '127.0.0.1', - ]; - - $this->dispatcher = $this->createMock(EventDispatcherInterface::class); - + $this->dispatcher = $this->createMock(EventDispatcherInterface::class); $this->crypt = $this->createMock(CryptInterface::class); $this->requestDataMapper = new PayFlexV4PosRequestDataMapper($this->dispatcher, $this->crypt); - $this->card = CreditCardFactory::create('5555444433332222', '2021', '12', '122', 'ahmet', CreditCardInterface::CARD_TYPE_VISA); } /** @@ -174,43 +158,38 @@ public function testCreate3DEnrollmentCheckData(array $order, ?CreditCardInterfa /** - * @return void + * @dataProvider createNonSecurePaymentRequestDataDataProvider */ - public function testCreateNonSecurePaymentRequestData(): void + public function testCreateNonSecurePaymentRequestData(array $order, CreditCardInterface $creditCard, string $txType, array $expected): void { - $order = $this->order; - $txType = PosInterface::TX_TYPE_PAY_AUTH; - $order['amount'] = 1000; - - $expectedValue = $this->getSampleNonSecurePaymentRequestData($this->account, $order, $txType, $this->card); - $actualData = $this->requestDataMapper->createNonSecurePaymentRequestData($this->account, $order, $txType, $this->card); + $actualData = $this->requestDataMapper->createNonSecurePaymentRequestData( + $this->account, + $order, + $txType, + $creditCard + ); - $this->assertEquals($expectedValue, $actualData); + $this->assertSame($expected, $actualData); } /** - * @return void + * @dataProvider createNonSecurePostAuthPaymentRequestDataDataProvider */ - public function testCreateNonSecurePostAuthPaymentRequestData(): void + public function testCreateNonSecurePostAuthPaymentRequestData(array $order, array $expected): void { - $order = $this->order; - $order['amount'] = 1000; + $actual = $this->requestDataMapper->createNonSecurePostAuthPaymentRequestData($this->account, $order); - $expectedValue = $this->getSampleNonSecurePaymentPostRequestData($this->account, $order); - $actual = $this->requestDataMapper->createNonSecurePostAuthPaymentRequestData($this->account, $order); - - $this->assertEquals($expectedValue, $actual); + $this->assertSame($expected, $actual); } - public function testCreateCancelRequestData(): void + /** + * @dataProvider createCancelRequestDataDataProvider + */ + public function testCreateCancelRequestData(array $order, array $expected): void { - $order = $this->order; - $order['transaction_id'] = '7022b92e-3aa1-44fb-86d4-33658c700c80'; - - $expectedValue = $this->getSampleCancelRequestData(); - $actualData = $this->requestDataMapper->createCancelRequestData($this->account, $order); + $actualData = $this->requestDataMapper->createCancelRequestData($this->account, $order); - $this->assertEquals($expectedValue, $actualData); + $this->assertSame($expected, $actualData); } /** @@ -226,12 +205,10 @@ public function testCreateRefundRequestData(array $order, string $txType, array } /** - * @return void + * @dataProvider create3DFormDataDataProvider */ - public function testCreate3DFormData(): void + public function testCreate3DFormData(array $bankResponse, array $expected): void { - $expectedValue = $this->getSample3DFormDataFromEnrollmentResponse(); - $this->dispatcher->expects(self::never()) ->method('dispatch'); @@ -242,10 +219,10 @@ public function testCreate3DFormData(): void null, null, null, - $this->getSampleEnrollmentSuccessResponseDataProvider()['Message']['VERes'] + $bankResponse ); - $this->assertEquals($expectedValue, $actualData); + $this->assertSame($expected, $actualData); } /** @@ -329,14 +306,22 @@ public static function getSampleEnrollmentSuccessResponseDataProvider(): array ]; } - private function getSampleCancelRequestData(): array + public static function createCancelRequestDataDataProvider(): array { return [ - 'MerchantId' => '000000000111111', - 'Password' => '3XTgER89as', - 'TransactionType' => 'Cancel', - 'ReferenceTransactionId' => '7022b92e-3aa1-44fb-86d4-33658c700c80', - 'ClientIp' => '127.0.0.1', + [ + 'order' => [ + 'transaction_id' => '7022b92e-3aa1-44fb-86d4-33658c700c80', + 'ip' => '127.0.0.1', + ], + 'expected' => [ + 'MerchantId' => '000000000111111', + 'Password' => '3XTgER89as', + 'TransactionType' => 'Cancel', + 'ReferenceTransactionId' => '7022b92e-3aa1-44fb-86d4-33658c700c80', + 'ClientIp' => '127.0.0.1', + ], + ], ]; } @@ -438,7 +423,14 @@ public static function three3DEnrollmentRequestDataDataProvider(): \Generator 'ip' => '127.0.0.1', ]; - $card = new CreditCard('5555444433332222', new \DateTimeImmutable('2021-12-01'), '122', 'ahmet', CreditCardInterface::CARD_TYPE_VISA); + $card = CreditCardFactory::create( + '5555444433332222', + '2021', + '12', + '122', + 'ahmet', + CreditCardInterface::CARD_TYPE_VISA + ); yield [ 'order' => $order, @@ -550,67 +542,86 @@ public static function refundRequestDataProvider(): array ]; } - /** - * @param PayFlexAccount $posAccount - * @param array $order - * @param string $txType - * @param CreditCardInterface $creditCard - * - * @return array - */ - private function getSampleNonSecurePaymentRequestData(AbstractPosAccount $posAccount, array $order, string $txType, CreditCardInterface $creditCard): array + public static function createNonSecurePaymentRequestDataDataProvider(): array { + $creditCard = CreditCardFactory::create( + '5555444433332222', + '2021', + '12', + '122', + 'ahmet', + CreditCardInterface::CARD_TYPE_VISA + ); + return [ - 'MerchantId' => $posAccount->getClientId(), - 'Password' => $posAccount->getPassword(), - 'TerminalNo' => $posAccount->getTerminalId(), - 'TransactionType' => $this->requestDataMapper->mapTxType($txType), - 'OrderId' => $order['id'], - 'CurrencyAmount' => '1000.00', - 'CurrencyCode' => 949, - 'ClientIp' => $order['ip'], - 'TransactionDeviceSource' => 0, - 'Pan' => $creditCard->getNumber(), - 'Expiry' => '202112', - 'Cvv' => $creditCard->getCvv(), + [ + 'order' => [ + 'id' => 'order123', + 'amount' => 5, + 'ip' => '127.0.0.1', + ], + 'card' => $creditCard, + 'tx_type' => PosInterface::TX_TYPE_PAY_AUTH, + 'expected' => [ + 'MerchantId' => '000000000111111', + 'Password' => '3XTgER89as', + 'TerminalNo' => 'VP999999', + 'TransactionType' => 'Sale', + 'OrderId' => 'order123', + 'CurrencyAmount' => '5.00', + 'CurrencyCode' => '949', + 'ClientIp' => '127.0.0.1', + 'TransactionDeviceSource' => '0', + 'Pan' => $creditCard->getNumber(), + 'Expiry' => '202112', + 'Cvv' => $creditCard->getCvv(), + ], + ], ]; } - /** - * @param PayFlexAccount $posAccount - * @param array $order - * - * @return array - */ - private function getSampleNonSecurePaymentPostRequestData(AbstractPosAccount $posAccount, array $order): array + public static function createNonSecurePostAuthPaymentRequestDataDataProvider(): array { return [ - 'MerchantId' => $posAccount->getClientId(), - 'Password' => $posAccount->getPassword(), - 'TerminalNo' => $posAccount->getTerminalId(), - 'TransactionType' => 'Capture', - 'ReferenceTransactionId' => $order['id'], - 'CurrencyAmount' => '1000.00', - 'CurrencyCode' => '949', - 'ClientIp' => $order['ip'], + [ + 'order' => [ + 'id' => 'order123', + 'amount' => 1000, + 'ip' => '127.0.0.1', + ], + 'expected' => [ + 'MerchantId' => '000000000111111', + 'Password' => '3XTgER89as', + 'TerminalNo' => 'VP999999', + 'TransactionType' => 'Capture', + 'ReferenceTransactionId' => 'order123', + 'CurrencyAmount' => '1000.00', + 'CurrencyCode' => '949', + 'ClientIp' => '127.0.0.1', + ], + ], ]; } /** * @return array */ - private function getSample3DFormDataFromEnrollmentResponse(): array + public static function create3DFormDataDataProvider(): array { - $inputs = [ - 'PaReq' => 'PaReq2', - 'TermUrl' => 'TermUrl2', - 'MD' => 'MD3', - ]; - return [ - 'gateway' => 'http', - 'method' => 'POST', - 'inputs' => $inputs, + [ + 'response' => self::getSampleEnrollmentSuccessResponseDataProvider()['Message']['VERes'], + 'expected' => [ + 'gateway' => 'http', + 'method' => 'POST', + 'inputs' => [ + + 'PaReq' => 'PaReq2', + 'TermUrl' => 'TermUrl2', + 'MD' => 'MD3', + ], + ], + ], ]; } } diff --git a/tests/Unit/DataMapper/ResponseDataMapper/PayFlexV4PosResponseDataMapperTest.php b/tests/Unit/DataMapper/ResponseDataMapper/PayFlexV4PosResponseDataMapperTest.php index d20782d4..9396002e 100644 --- a/tests/Unit/DataMapper/ResponseDataMapper/PayFlexV4PosResponseDataMapperTest.php +++ b/tests/Unit/DataMapper/ResponseDataMapper/PayFlexV4PosResponseDataMapperTest.php @@ -8,6 +8,7 @@ use Mews\Pos\Crypt\CryptInterface; use Mews\Pos\DataMapper\RequestDataMapper\PayFlexV4PosRequestDataMapper; use Mews\Pos\DataMapper\ResponseDataMapper\PayFlexV4PosResponseDataMapper; +use Mews\Pos\Exceptions\NotImplementedException; use Mews\Pos\PosInterface; use PHPUnit\Framework\TestCase; use Psr\EventDispatcher\EventDispatcherInterface; @@ -15,6 +16,7 @@ /** * @covers \Mews\Pos\DataMapper\ResponseDataMapper\PayFlexV4PosResponseDataMapper + * @covers \Mews\Pos\DataMapper\ResponseDataMapper\AbstractResponseDataMapper */ class PayFlexV4PosResponseDataMapperTest extends TestCase { @@ -131,6 +133,30 @@ public function testMapStatusResponse(array $responseData, array $expectedData): $this->assertSame($expectedData, $actualData); } + public function testMap3DPayResponseData(): void + { + $this->expectException(NotImplementedException::class); + $this->responseDataMapper->map3DPayResponseData([], PosInterface::TX_TYPE_PAY_AUTH, []); + } + + public function testMap3DHostResponseData(): void + { + $this->expectException(NotImplementedException::class); + $this->responseDataMapper->map3DHostResponseData([], PosInterface::TX_TYPE_PAY_AUTH, []); + } + + public function testMapHistoryResponse(): void + { + $this->expectException(NotImplementedException::class); + $this->responseDataMapper->mapHistoryResponse([]); + } + + public function testMapOrderHistoryResponse(): void + { + $this->expectException(NotImplementedException::class); + $this->responseDataMapper->mapOrderHistoryResponse([]); + } + public static function statusTestDataProvider(): iterable { yield 'fail1' => [