Skip to content

Commit

Permalink
tests - working on coverage
Browse files Browse the repository at this point in the history
  • Loading branch information
nuryagdym committed Mar 29, 2024
1 parent 94a88c3 commit 342f5a7
Show file tree
Hide file tree
Showing 5 changed files with 80 additions and 15 deletions.
6 changes: 3 additions & 3 deletions src/Serializer/KuveytPosSerializer.php
Original file line number Diff line number Diff line change
Expand Up @@ -16,8 +16,8 @@
use Mews\Pos\PosInterface;
use Symfony\Component\Serializer\Encoder\JsonEncoder;
use Symfony\Component\Serializer\Encoder\XmlEncoder;
use Symfony\Component\Serializer\Exception\NotEncodableValueException;
use Symfony\Component\Serializer\Serializer;
use Throwable;

class KuveytPosSerializer implements SerializerInterface
{
Expand Down Expand Up @@ -75,13 +75,13 @@ public function decode(string $data, string $txType): array

try {
return $this->serializer->decode($data, XmlEncoder::FORMAT);
} catch (Throwable $throwable) {
} catch (NotEncodableValueException $notEncodableValueException) {
if ($this->isHTML($data)) {
// 3D form data icin enrollment istegi gonderiyoruz, o istegin cevabi icinde form olan HTML donuyor.
return $this->transformReceived3DFormData($data);
}

throw new Exception($data, $throwable->getCode(), $throwable);
throw new Exception($data, $notEncodableValueException->getCode(), $notEncodableValueException);
}
}

Expand Down
2 changes: 1 addition & 1 deletion tests/Unit/Gateways/KuveytPosTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -127,7 +127,7 @@ protected function setUp(): void
);

$this->pos->setTestMode(true);

$this->card = CreditCardFactory::createForGateway(
$this->pos,
'4155650100416111',
Expand Down
38 changes: 34 additions & 4 deletions tests/Unit/Serializer/KuveytPosSerializerTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,9 @@ public function testSupports(): void
public function testEncode(array $data, string $txType, $expected): void
{
$result = $this->serializer->encode($data, $txType);
if (is_string($expected)) {
$expected = str_replace(["\r"], '', $expected);
}

$this->assertSame($expected, $result);
}
Expand Down Expand Up @@ -74,6 +77,15 @@ public function testDecodeJson(string $input, string $txType, array $expected):
$this->assertSame($expected, $actual);
}

/**
* @dataProvider decodeExceptionDataProvider
*/
public function testDecodeException(string $input, string $txType, string $exceptionClass): void
{
$this->expectException($exceptionClass);

$this->serializer->decode($input, $txType);
}

public static function encodeDataProvider(): Generator
{
Expand All @@ -95,6 +107,14 @@ public static function encodeDataProvider(): Generator
'txType' => PosInterface::TX_TYPE_STATUS,
'expected' => ['abc' => 1],
];

yield 'test_pay' => [
'input' => ['abc' => 1],
'txType' => PosInterface::TX_TYPE_PAY_AUTH,
'expected' => '<?xml version="1.0" encoding="ISO-8859-1"?>
<KuveytTurkVPosMessage><abc>1</abc></KuveytTurkVPosMessage>
',
];
}

public static function decodeHtmlDataProvider(): array
Expand Down Expand Up @@ -129,6 +149,7 @@ public static function decodeHtmlDataProvider(): array
</body>
</html>
HTML;

return [
[
'html' => '<!DOCTYPE html><html xmlns="http://www.w3.org/1999/xhtml"><head runat="server"><title></title></head><body onload="OnLoadEvent();"><form name="downloadForm" action="https://boa.kuveytturk.com.tr/sanalposservice/Home/ThreeDModelPayGate" method="POST"><input type="hidden" name="AuthenticationResponse" value="%3C%3Fxml+version%3D%221.0%22+encoding%3D%22UTF-8%22%3F%3E%3CVPosTransactionResponseContract%3E%3CVPosMessage%3E%3CAPIVersion%3E1.0.0%3C%2FAPIVersion%3E%3COkUrl%3Ehttp%3A%2F%2Flocalhost%3A44785%2FHome%2FSuccess%3C%2FOkUrl%3E%3CFailUrl%3Ehttp%3A%2F%2Flocalhost%3A44785%2FHome%2FFail%3C%2FFailUrl%3E%3CHashData%3ElYJYMi%2FgVO9MWr32Pshaa%2FzAbSHY%3D%3C%2FHashData%3E%3CMerchantId%3E80%3C%2FMerchantId%3E%3CSubMerchantId%3E0%3C%2FSubMerchantId%3E%3CCustomerId%3E400235%3C%2FCustomerId%3E%3CUserName%3Eapiuser%3C%2FUserName%3E%3CCardNumber%3E4025502306586032%3C%2FCardNumber%3E%3CCardHolderName%3Eafafa%3C%2FCardHolderName%3E%3CCardType%3EMasterCard%3C%2FCardType%3E%3CBatchID%3E0%3C%2FBatchID%3E%3CTransactionType%3ESale%3C%2FTransactionType%3E%3CInstallmentCount%3E0%3C%2FInstallmentCount%3E%3CAmount%3E100%3C%2FAmount%3E%3CDisplayAmount%3E100%3C%2FDisplayAmount%3E%3CMerchantOrderId%3EOrder+123%3C%2FMerchantOrderId%3E%3CFECAmount%3E0%3C%2FFECAmount%3E%3CCurrencyCode%3E0949%3C%2FCurrencyCode%3E%3CQeryId%3E0%3C%2FQeryId%3E%3CDebtId%3E0%3C%2FDebtId%3E%3CSurchargeAmount%3E0%3C%2FSurchargeAmount%3E%3CSGKDebtAmount%3E0%3C%2FSGKDebtAmount%3E%3CTransactionSecurity%3E3%3C%2FTransactionSecurity%3E%3CTransactionSide%3EAuto%3C%2FTransactionSide%3E%3CEntryGateMethod%3EVPOS_ThreeDModelPayGate%3C%2FEntryGateMethod%3E%3C%2FVPosMessage%3E%3CIsEnrolled%3Etrue%3C%2FIsEnrolled%3E%3CIsVirtual%3Efalse%3C%2FIsVirtual%3E%3COrderId%3E0%3C%2FOrderId%3E%3CTransactionTime%3E0001-01-01T00%3A00%3A00%3C%2FTransactionTime%3E%3CMD%3E67YtBfBRTZ0XBKnAHi8c%2FA%3D%3D%3C%2FMD%3E%3CAuthenticationPacket%3EWYGDgSIrSHDtYwF%2FWEN%2BnfwX63sppA%3D%3C%2FAuthenticationPacket%3E%3CACSURL%3Ehttps%3A%2F%2Facs.bkm.com.tr%2Fmdpayacs%2Fpareq%3C%2FACSURL%3E%3C%2FVPosTransactionResponseContract%3E"><noscript><center>Please click the submit button below.<br><input type="submit" name="submit" value="Submit"></center></noscript></form><script language="Javascript">function OnLoadEvent() {document.downloadForm.submit();}</script></body></html>',
Expand All @@ -155,7 +176,7 @@ public static function decodeHtmlDataProvider(): array
],
],
],
'3d_auth_fail' => [
'3d_auth_fail' => [
// fail durum testi
'html' => '<!DOCTYPE html><html xmlns="http://www.w3.org/1999/xhtml"><head runat="server"> <title></title></head><body onload="OnLoadEvent();"> <form name="downloadForm" action="http://localhost/finansbank-payfor/3d/response.php" method="POST"> <input type="hidden" name="AuthenticationResponse" value="%3c%3fxml+version%3d%221.0%22+encoding%3d%22utf-8%22%3f%3e%3cVPosTransactionResponseContract+xmlns%3axsd%3d%22http%3a%2f%2fwww.w3.org%2f2001%2fXMLSchema%22+xmlns%3axsi%3d%22http%3a%2f%2fwww.w3.org%2f2001%2fXMLSchema-instance%22%3e%3cIsEnrolled%3etrue%3c%2fIsEnrolled%3e%3cIsVirtual%3efalse%3c%2fIsVirtual%3e%3cResponseCode%3eHashDataError%3c%2fResponseCode%3e%3cResponseMessage%3e%c5%9eifrelenen+veriler+(Hashdata)+uyu%c5%9fmamaktad%c4%b1r.%3c%2fResponseMessage%3e%3cOrderId%3e0%3c%2fOrderId%3e%3cTransactionTime%3e0001-01-01T00%3a00%3a00%3c%2fTransactionTime%3e%3cMerchantOrderId%3e2020110828BC%3c%2fMerchantOrderId%3e%3cReferenceId%3efbab348b4c074d1b9a5247471d91f5d1%3c%2fReferenceId%3e%3cMerchantId%3e496%3c%2fMerchantId%3e%3cBusinessKey%3e0%3c%2fBusinessKey%3e%3c%2fVPosTransactionResponseContract%3e"> <!-- To support javascript unaware/disabled browsers --> <noscript> <center>Please click the submit button below.<br> <input type="submit" name="submit" value="Submit"></center> </noscript> </form> <script language="Javascript"> function OnLoadEvent() {document.downloadForm.submit();} </script></body></html>',
'expected' => [
Expand All @@ -168,10 +189,10 @@ public static function decodeHtmlDataProvider(): array
],
[
// test with custom APM_DO_NOT_TOUCH element
'html' => $htmlWithCustomHtmlElement,
'html' => $htmlWithCustomHtmlElement,
'expected' => [
'gateway' => 'https://site/gateway/3d/fail?uuid=BR7z5PDu6c',
'form_inputs' => [
'gateway' => 'https://site/gateway/3d/fail?uuid=BR7z5PDu6c',
'form_inputs' => [
'AuthenticationResponse' => '%3c%3fxml+version%3d%221.0%22+encoding%3d%22utf-8%22%3f%3e%3cVPosTransactionResponseContract+xmlns%3axsd%3d%22http%3a%2f%2fwww.w3.org%2f2001%2fXMLSchema%22+xmlns%3axsi%3d%22http%3a%2f%2fwww.w3.org%2f2001%2fXMLSchema-instance%22%3e%3cIsEnrolled%3etrue%3c%2fIsEnrolled%3e%3cIsVirtual%3efalse%3c%2fIsVirtual%3e%3cResponseCode%3ePosMerchantIPError%3c%2fResponseCode%3e%3cResponseMessage%3eIP+adresi+tan%c4%b1ml%c4%b1+de%c4%9fildir.%3c%2fResponseMessage%3e%3cOrderId%3e0%3c%2fOrderId%3e%3cTransactionTime%3e0001-01-01T00%3a00%3a00%3c%2fTransactionTime%3e%3cMerchantOrderId%3eEak3mC1eW5%3c%2fMerchantOrderId%3e%3cReferenceId%3ea92e57f52ac443538bdb71b10a6c6fe7%3c%2fReferenceId%3e%3cMerchantId%3e80123%3c%2fMerchantId%3e%3cBusinessKey%3e0%3c%2fBusinessKey%3e%3c%2fVPosTransactionResponseContract%3e',
],
],
Expand Down Expand Up @@ -254,4 +275,13 @@ public static function decodeJsonDataProvider(): Generator
'expected' => ['abc' => 1],
];
}

public static function decodeExceptionDataProvider(): Generator
{
yield 'test1' => [
'input' => '',
'txType' => PosInterface::TX_TYPE_PAY_AUTH,
'expected_exception_class' => \Exception::class,
];
}
}
26 changes: 19 additions & 7 deletions tests/Unit/Serializer/PayFlexCPV4PosSerializerTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -6,12 +6,12 @@
namespace Mews\Pos\Tests\Unit\Serializer;

use DomainException;
use Exception;
use Generator;
use Mews\Pos\Gateways\PayFlexCPV4Pos;
use Mews\Pos\PosInterface;
use Mews\Pos\Serializer\PayFlexCPV4PosSerializer;
use PHPUnit\Framework\TestCase;
use Symfony\Component\Serializer\Exception\NotEncodableValueException;

/**
* @covers \Mews\Pos\Serializer\PayFlexCPV4PosSerializer
Expand All @@ -34,16 +34,16 @@ public function testSupports(): void
$this->assertTrue($supports);
}

public function testDecodeException(): void
/**
* @dataProvider decodeExceptionDataProvider
*/
public function testDecodeException(string $input, string $exceptionClass): void
{
$data = "<html><head><title>Request Rejected</title></head><body>The requested URL was rejected. Please consult with your administrator.<br><br>Your support ID is: 9487950831267702255<br><br><a href='javascript:history.back();'>[Go Back]</a></body></html>";
$this->expectException(Exception::class);
$this->expectExceptionMessage($data);
$this->expectException($exceptionClass);

$this->serializer->decode($data);
$this->serializer->decode($input);
}


/**
* @dataProvider encodeDataProvider
*/
Expand Down Expand Up @@ -131,4 +131,16 @@ public static function encodeNonPaymentDataProvider(): Generator
'expected' => '<VposRequest><MerchantId>000000000111111</MerchantId><Password>3XTgER89as</Password><TransactionType>Sale</TransactionType><OrderId>order222</OrderId><CurrencyAmount>100.00</CurrencyAmount><CurrencyCode>949</CurrencyCode><ClientIp>127.0.0.1</ClientIp><TransactionDeviceSource>0</TransactionDeviceSource><Pan>5555444433332222</Pan><Expiry>202112</Expiry><Cvv>122</Cvv></VposRequest>',
];
}

public static function decodeExceptionDataProvider(): Generator
{
yield 'test1' => [
'input' => "<html><head><title>Request Rejected</title></head><body>The requested URL was rejected. Please consult with your administrator.<br><br>Your support ID is: 11795445874629392419<br><br><a href='javascript:history.back();'>[Go Back]</a></body></html>",
'expected_exception_class' => \Exception::class,
];
yield 'test2' => [
'input' => '',
'expected_exception_class' => NotEncodableValueException::class,
];
}
}
23 changes: 23 additions & 0 deletions tests/Unit/Serializer/PayFlexV4PosSerializerTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
use Mews\Pos\PosInterface;
use Mews\Pos\Serializer\PayFlexV4PosSerializer;
use PHPUnit\Framework\TestCase;
use Symfony\Component\Serializer\Exception\NotEncodableValueException;

/**
* @covers \Mews\Pos\Serializer\PayFlexV4PosSerializer
Expand Down Expand Up @@ -66,6 +67,16 @@ public function testDecode(string $input, array $expected): void
$this->assertSame($expected, $actual);
}

/**
* @dataProvider decodeExceptionDataProvider
*/
public function testDecodeException(string $input, string $exceptionClass): void
{
$this->expectException($exceptionClass);

$this->serializer->decode($input);
}

public static function decodeDataProvider(): Generator
{
yield 'test1' => [
Expand All @@ -78,6 +89,18 @@ public static function decodeDataProvider(): Generator
];
}

public static function decodeExceptionDataProvider(): Generator
{
yield 'test1' => [
'input' => "<html><head><title>Request Rejected</title></head><body>The requested URL was rejected. Please consult with your administrator.<br><br>Your support ID is: 11795445874629392419<br><br><a href='javascript:history.back();'>[Go Back]</a></body></html>",
'expected_exception_class' => \Exception::class,
];
yield 'test2' => [
'input' => '',
'expected_exception_class' => NotEncodableValueException::class,
];
}

public static function encodeDataProvider(): Generator
{
yield 'test1' => [
Expand Down

0 comments on commit 342f5a7

Please sign in to comment.