Skip to content

Commit

Permalink
tests - cover hashmismatchexception lines
Browse files Browse the repository at this point in the history
  • Loading branch information
mustapayev committed Sep 6, 2024
1 parent d34ef10 commit 7864a8e
Show file tree
Hide file tree
Showing 7 changed files with 305 additions and 7 deletions.
65 changes: 65 additions & 0 deletions tests/Unit/Gateways/EstPosTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
use Mews\Pos\Entity\Account\EstPosAccount;
use Mews\Pos\Entity\Card\CreditCardInterface;
use Mews\Pos\Event\RequestDataPreparedEvent;
use Mews\Pos\Exceptions\HashMismatchException;
use Mews\Pos\Exceptions\UnsupportedTransactionTypeException;
use Mews\Pos\Factory\AccountFactory;
use Mews\Pos\Factory\CreditCardFactory;
Expand Down Expand Up @@ -205,6 +206,23 @@ public function testMake3DHostPaymentSuccess(): void
$this->assertTrue($pos->isSuccess());
}

public function testMake3DHostPaymentHashMismatchException(): void
{
$data = EstPosResponseDataMapperTest::threeDHostPaymentDataProvider()['success1']['paymentData'];
$request = Request::create('', 'POST', $data);

$this->cryptMock->expects(self::once())
->method('check3DHash')
->with($this->account, $data)
->willReturn(false);

$this->responseMapperMock->expects(self::never())
->method('map3DHostResponseData');

$this->expectException(HashMismatchException::class);
$this->pos->make3DHostPayment($request, [], PosInterface::TX_TYPE_PAY_AUTH);
}

/**
* @return void
*/
Expand Down Expand Up @@ -233,6 +251,23 @@ public function testMake3DPayPaymentSuccess(): void
$this->assertTrue($pos->isSuccess());
}

public function testMake3DPayPaymentHashMismatchException(): void
{
$data = EstPosResponseDataMapperTest::threeDPayPaymentDataProvider()['success1']['paymentData'];
$request = Request::create('', 'POST', $data);

$this->cryptMock->expects(self::once())
->method('check3DHash')
->with($this->account, $data)
->willReturn(false);

$this->responseMapperMock->expects(self::never())
->method('map3DPayResponseData');

$this->expectException(HashMismatchException::class);
$this->pos->make3DPayPayment($request, [], PosInterface::TX_TYPE_PAY_AUTH);
}

/**
* @dataProvider statusDataProvider
*/
Expand Down Expand Up @@ -467,6 +502,36 @@ public function testMake3DPayment(
$this->assertSame($isSuccess, $this->pos->isSuccess());
}

public function testMake3DPaymentHashMismatchException(): void
{
$data = EstPosResponseDataMapperTest::threeDPaymentDataProvider()['3d_auth_success_payment_fail']['threeDResponseData'];
$request = Request::create('', 'POST', $data);

$this->cryptMock->expects(self::once())
->method('check3DHash')
->with($this->account, $data)
->willReturn(false);

$this->responseMapperMock->expects(self::once())
->method('is3dAuthSuccess')
->willReturn(true);

$this->responseMapperMock->expects(self::never())
->method('map3DPaymentData');
$this->requestMapperMock->expects(self::never())
->method('create3DPaymentRequestData');
$this->serializerMock->expects(self::never())
->method('encode');
$this->serializerMock->expects(self::never())
->method('decode');
$this->eventDispatcherMock->expects(self::never())
->method('dispatch');

$this->expectException(HashMismatchException::class);
$this->pos->make3DPayment($request, [], PosInterface::TX_TYPE_PAY_AUTH);
}


/**
* @dataProvider makeRegularPaymentDataProvider
*/
Expand Down
42 changes: 40 additions & 2 deletions tests/Unit/Gateways/GarantiPosTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
use Mews\Pos\Entity\Account\GarantiPosAccount;
use Mews\Pos\Entity\Card\CreditCardInterface;
use Mews\Pos\Event\RequestDataPreparedEvent;
use Mews\Pos\Exceptions\HashMismatchException;
use Mews\Pos\Exceptions\UnsupportedPaymentModelException;
use Mews\Pos\Factory\AccountFactory;
use Mews\Pos\Factory\CreditCardFactory;
Expand Down Expand Up @@ -244,6 +245,35 @@ public function testMake3DPayment(
$this->assertSame($isSuccess, $this->pos->isSuccess());
}

public function testMake3DPaymentHashMismatchException(): void
{
$data = GarantiPosResponseDataMapperTest::threeDPaymentDataProvider()['paymentFail1']['threeDResponseData'];
$request = Request::create('', 'POST', $data);

$this->cryptMock->expects(self::once())
->method('check3DHash')
->with($this->account, $data)
->willReturn(false);

$this->responseMapperMock->expects(self::once())
->method('is3dAuthSuccess')
->willReturn(true);

$this->responseMapperMock->expects(self::never())
->method('map3DPaymentData');
$this->requestMapperMock->expects(self::never())
->method('create3DPaymentRequestData');
$this->serializerMock->expects(self::never())
->method('encode');
$this->serializerMock->expects(self::never())
->method('decode');
$this->eventDispatcherMock->expects(self::never())
->method('dispatch');

$this->expectException(HashMismatchException::class);
$this->pos->make3DPayment($request, [], PosInterface::TX_TYPE_PAY_AUTH);
}

public function testMake3DHostPayment(): void
{
$request = Request::create('', 'POST');
Expand Down Expand Up @@ -522,7 +552,11 @@ public static function make3DPaymentDataProvider(): array
'3d_auth_success_payment_fail' => [
'order' => GarantiPosResponseDataMapperTest::threeDPaymentDataProvider()['paymentFail1']['order'],
'txType' => GarantiPosResponseDataMapperTest::threeDPaymentDataProvider()['paymentFail1']['txType'],
'request' => Request::create('', 'POST', GarantiPosResponseDataMapperTest::threeDPaymentDataProvider()['paymentFail1']['threeDResponseData']),
'request' => Request::create(
'',
'POST',
GarantiPosResponseDataMapperTest::threeDPaymentDataProvider()['paymentFail1']['threeDResponseData']
),
'paymentResponse' => GarantiPosResponseDataMapperTest::threeDPaymentDataProvider()['paymentFail1']['paymentData'],
'expected' => GarantiPosResponseDataMapperTest::threeDPaymentDataProvider()['paymentFail1']['expectedData'],
'is3DSuccess' => true,
Expand All @@ -531,7 +565,11 @@ public static function make3DPaymentDataProvider(): array
'success' => [
'order' => GarantiPosResponseDataMapperTest::threeDPaymentDataProvider()['success1']['order'],
'txType' => GarantiPosResponseDataMapperTest::threeDPaymentDataProvider()['success1']['txType'],
'request' => Request::create('', 'POST', GarantiPosResponseDataMapperTest::threeDPaymentDataProvider()['success1']['threeDResponseData']),
'request' => Request::create(
'',
'POST',
GarantiPosResponseDataMapperTest::threeDPaymentDataProvider()['success1']['threeDResponseData']
),
'paymentResponse' => GarantiPosResponseDataMapperTest::threeDPaymentDataProvider()['success1']['paymentData'],
'expected' => GarantiPosResponseDataMapperTest::threeDPaymentDataProvider()['success1']['expectedData'],
'is3DSuccess' => true,
Expand Down
28 changes: 28 additions & 0 deletions tests/Unit/Gateways/KuveytPosTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -353,6 +353,34 @@ public function testMake3DPayment(
$this->assertSame($isSuccess, $this->pos->isSuccess());
}

public function testMake3DPaymentException(): void
{
$request = Request::create('');

$this->cryptMock->expects(self::never())
->method('check3DHash');

$this->responseMapperMock->expects(self::never())
->method('extractMdStatus');

$this->responseMapperMock->expects(self::never())
->method('is3dAuthSuccess');


$this->responseMapperMock->expects(self::never())
->method('map3DPaymentData');

$this->requestMapperMock->expects(self::never())
->method('create3DPaymentRequestData');
$this->serializerMock->expects(self::never())
->method('encode');
$this->serializerMock->expects(self::never())
->method('decode');

$this->expectException(\LogicException::class);
$this->pos->make3DPayment($request, [], PosInterface::TX_TYPE_PAY_AUTH);
}

/**
* @dataProvider makeRegularPaymentDataProvider
*/
Expand Down
48 changes: 45 additions & 3 deletions tests/Unit/Gateways/PayForTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
use Mews\Pos\Entity\Account\PayForAccount;
use Mews\Pos\Entity\Card\CreditCardInterface;
use Mews\Pos\Event\RequestDataPreparedEvent;
use Mews\Pos\Exceptions\HashMismatchException;
use Mews\Pos\Factory\AccountFactory;
use Mews\Pos\Factory\CreditCardFactory;
use Mews\Pos\Gateways\PayForPos;
Expand Down Expand Up @@ -258,6 +259,35 @@ public function testMake3DPayment(
$this->assertSame($isSuccess, $this->pos->isSuccess());
}

public function testMake3DPaymentHashMismatchException(): void
{
$data = PayForPosResponseDataMapperTest::threeDPaymentDataProvider()['success1']['threeDResponseData'];
$request = Request::create('', 'POST', $data);

$this->cryptMock->expects(self::once())
->method('check3DHash')
->with($this->account, $data)
->willReturn(false);

$this->responseMapperMock->expects(self::once())
->method('is3dAuthSuccess')
->willReturn(true);

$this->responseMapperMock->expects(self::never())
->method('map3DPaymentData');
$this->requestMapperMock->expects(self::never())
->method('create3DPaymentRequestData');
$this->serializerMock->expects(self::never())
->method('encode');
$this->serializerMock->expects(self::never())
->method('decode');
$this->eventDispatcherMock->expects(self::never())
->method('dispatch');

$this->expectException(HashMismatchException::class);
$this->pos->make3DPayment($request, [], PosInterface::TX_TYPE_PAY_AUTH);
}

/**
* @return void
*/
Expand Down Expand Up @@ -556,7 +586,11 @@ public static function make3DPaymentDataProvider(): array
'auth_fail' => [
'order' => PayForPosResponseDataMapperTest::threeDPaymentDataProvider()['auth_fail1']['order'],
'txType' => PayForPosResponseDataMapperTest::threeDPaymentDataProvider()['auth_fail1']['txType'],
'request' => Request::create('', 'POST', PayForPosResponseDataMapperTest::threeDPaymentDataProvider()['auth_fail1']['threeDResponseData']),
'request' => Request::create(
'',
'POST',
PayForPosResponseDataMapperTest::threeDPaymentDataProvider()['auth_fail1']['threeDResponseData']
),
'paymentResponse' => PayForPosResponseDataMapperTest::threeDPaymentDataProvider()['auth_fail1']['paymentData'],
'expected' => PayForPosResponseDataMapperTest::threeDPaymentDataProvider()['auth_fail1']['expectedData'],
'is3DSuccess' => false,
Expand All @@ -565,7 +599,11 @@ public static function make3DPaymentDataProvider(): array
'order_number_already_exist' => [
'order' => PayForPosResponseDataMapperTest::threeDPaymentDataProvider()['order_number_already_exist']['order'],
'txType' => PayForPosResponseDataMapperTest::threeDPaymentDataProvider()['order_number_already_exist']['txType'],
'request' => Request::create('', 'POST', PayForPosResponseDataMapperTest::threeDPaymentDataProvider()['order_number_already_exist']['threeDResponseData']),
'request' => Request::create(
'',
'POST',
PayForPosResponseDataMapperTest::threeDPaymentDataProvider()['order_number_already_exist']['threeDResponseData']
),
'paymentResponse' => PayForPosResponseDataMapperTest::threeDPaymentDataProvider()['order_number_already_exist']['paymentData'],
'expected' => PayForPosResponseDataMapperTest::threeDPaymentDataProvider()['order_number_already_exist']['expectedData'],
'is3DSuccess' => false,
Expand All @@ -574,7 +612,11 @@ public static function make3DPaymentDataProvider(): array
'success' => [
'order' => PayForPosResponseDataMapperTest::threeDPaymentDataProvider()['success1']['order'],
'txType' => PayForPosResponseDataMapperTest::threeDPaymentDataProvider()['success1']['txType'],
'request' => Request::create('', 'POST', PayForPosResponseDataMapperTest::threeDPaymentDataProvider()['success1']['threeDResponseData']),
'request' => Request::create(
'',
'POST',
PayForPosResponseDataMapperTest::threeDPaymentDataProvider()['success1']['threeDResponseData']
),
'paymentResponse' => PayForPosResponseDataMapperTest::threeDPaymentDataProvider()['success1']['paymentData'],
'expected' => PayForPosResponseDataMapperTest::threeDPaymentDataProvider()['success1']['expectedData'],
'is3DSuccess' => true,
Expand Down
43 changes: 43 additions & 0 deletions tests/Unit/Gateways/PosNetTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
use Mews\Pos\Entity\Account\PosNetAccount;
use Mews\Pos\Entity\Card\CreditCardInterface;
use Mews\Pos\Event\RequestDataPreparedEvent;
use Mews\Pos\Exceptions\HashMismatchException;
use Mews\Pos\Exceptions\UnsupportedPaymentModelException;
use Mews\Pos\Exceptions\UnsupportedTransactionTypeException;
use Mews\Pos\Factory\AccountFactory;
Expand Down Expand Up @@ -394,6 +395,48 @@ public function testMake3DPayment(
$this->assertSame($isSuccess, $this->pos->isSuccess());
}

public function testMake3DPaymentHashMismatchException(): void
{
$resolveResponse = PosNetResponseDataMapperTest::threeDPaymentDataProvider()['success1']['threeDResponseData'];
$request = Request::create(
'',
'POST',
$resolveResponse
);
$this->cryptMock->expects(self::once())
->method('check3DHash')
->with($this->account, $resolveResponse['oosResolveMerchantDataResponse'])
->willReturn(false);

$this->responseMapperMock->expects(self::once())
->method('is3dAuthSuccess')
->willReturn(true);

$resolveMerchantRequestData = [
'resolveMerchantRequestData',
];
$this->requestMapperMock->expects(self::once())
->method('create3DResolveMerchantRequestData')
->willReturn($resolveMerchantRequestData);

$this->requestMapperMock->expects(self::never())
->method('create3DPaymentRequestData');

$this->configureClientResponse(
PosInterface::TX_TYPE_PAY_AUTH,
'https://setmpos.ykb.com/PosnetWebService/XML',
$resolveMerchantRequestData,
'request-body',
'response-body',
$resolveResponse,
[],
PosInterface::MODEL_3D_SECURE
);

$this->expectException(HashMismatchException::class);
$this->pos->make3DPayment($request, [], PosInterface::TX_TYPE_PAY_AUTH);
}

public function testMake3DHostPayment(): void
{
$request = Request::create('', 'POST');
Expand Down
31 changes: 31 additions & 0 deletions tests/Unit/Gateways/PosNetV1PosTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
use Mews\Pos\Entity\Account\PosNetAccount;
use Mews\Pos\Entity\Card\CreditCardInterface;
use Mews\Pos\Event\RequestDataPreparedEvent;
use Mews\Pos\Exceptions\HashMismatchException;
use Mews\Pos\Exceptions\UnsupportedPaymentModelException;
use Mews\Pos\Exceptions\UnsupportedTransactionTypeException;
use Mews\Pos\Factory\AccountFactory;
Expand Down Expand Up @@ -251,6 +252,36 @@ public function testMake3DPayment(
$this->assertSame($isSuccess, $this->pos->isSuccess());
}

public function testMake3DPaymentHashMismatchException(): void
{
$dataSamples = iterator_to_array(PosNetV1PosResponseDataMapperTest::threeDPaymentDataProvider());
$data = $dataSamples['3d_auth_success_payment_fail']['threeDResponseData'];
$request = Request::create('', 'POST', $data);

$this->cryptMock->expects(self::once())
->method('check3DHash')
->with($this->account, $data)
->willReturn(false);

$this->responseMapperMock->expects(self::once())
->method('is3dAuthSuccess')
->willReturn(true);

$this->responseMapperMock->expects(self::never())
->method('map3DPaymentData');
$this->requestMapperMock->expects(self::never())
->method('create3DPaymentRequestData');
$this->serializerMock->expects(self::never())
->method('encode');
$this->serializerMock->expects(self::never())
->method('decode');
$this->eventDispatcherMock->expects(self::never())
->method('dispatch');

$this->expectException(HashMismatchException::class);
$this->pos->make3DPayment($request, [], PosInterface::TX_TYPE_PAY_AUTH);
}

public function testMake3DHostPayment(): void
{
$request = Request::create('', 'POST');
Expand Down
Loading

0 comments on commit 7864a8e

Please sign in to comment.