Skip to content

Commit

Permalink
test - added event examples into functional tests
Browse files Browse the repository at this point in the history
  • Loading branch information
nuryagdym committed Dec 26, 2023
1 parent 91a9a41 commit 53caeb4
Show file tree
Hide file tree
Showing 4 changed files with 293 additions and 5 deletions.
46 changes: 44 additions & 2 deletions tests/Functional/AkOdePosTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
namespace Mews\Pos\Tests\Functional;

use Mews\Pos\Entity\Card\CreditCardInterface;
use Mews\Pos\Event\RequestDataPreparedEvent;
use Mews\Pos\Factory\AccountFactory;
use Mews\Pos\Factory\CreditCardFactory;
use Mews\Pos\Factory\PosFactory;
Expand All @@ -19,6 +20,8 @@ class AkOdePosTest extends TestCase
use PaymentTestTrait;

private CreditCardInterface $card;

private EventDispatcher $eventDispatcher;

/** @var AkOdePos */
private PosInterface $pos;
Expand All @@ -38,7 +41,9 @@ protected function setUp(): void
'POS_ENT_Test_001!*!*',
);

$this->pos = PosFactory::createPosGateway($account, $config, new EventDispatcher());
$this->eventDispatcher = new EventDispatcher();

$this->pos = PosFactory::createPosGateway($account, $config, $this->eventDispatcher);
$this->pos->setTestMode(true);

$this->card = CreditCardFactory::create(
Expand All @@ -56,6 +61,14 @@ public function testNonSecurePaymentSuccess(): array
{
$order = $this->createPaymentOrder();

$this->eventDispatcher->addListener(
RequestDataPreparedEvent::class,
function (RequestDataPreparedEvent $event) use (&$eventIsThrown) {
$eventIsThrown = true;
$this->assertSame(PosInterface::TX_TYPE_PAY_AUTH, $event->getTxType());
$this->assertCount(13, $event->getRequestData());
});

$this->pos->payment(
PosInterface::MODEL_NON_SECURE,
$order,
Expand All @@ -68,6 +81,7 @@ public function testNonSecurePaymentSuccess(): array
$response = $this->pos->getResponse();
$this->assertIsArray($response);
$this->assertNotEmpty($response);
$this->assertTrue($eventIsThrown);

return $this->pos->getResponse();
}
Expand All @@ -79,12 +93,22 @@ public function testStatusSuccess(array $lastResponse): array
{
$statusOrder = $this->createStatusOrder(\get_class($this->pos), $lastResponse);

$eventIsThrown = false;
$this->eventDispatcher->addListener(
RequestDataPreparedEvent::class,
function (RequestDataPreparedEvent $event) use (&$eventIsThrown) {
$eventIsThrown = true;
$this->assertSame(PosInterface::TX_TYPE_STATUS, $event->getTxType());
$this->assertCount(6, $event->getRequestData());
});

$this->pos->status($statusOrder);

$this->assertTrue($this->pos->isSuccess());
$response = $this->pos->getResponse();
$this->assertIsArray($response);
$this->assertNotEmpty($response);
$this->assertTrue($eventIsThrown);

return $lastResponse;
}
Expand All @@ -97,25 +121,43 @@ public function testCancelSuccess(array $lastResponse): void
{
$statusOrder = $this->createCancelOrder(\get_class($this->pos), $lastResponse);

$eventIsThrown = false;
$this->eventDispatcher->addListener(
RequestDataPreparedEvent::class,
function (RequestDataPreparedEvent $event) use (&$eventIsThrown) {
$eventIsThrown = true;
$this->assertSame(PosInterface::TX_TYPE_CANCEL, $event->getTxType());
$this->assertCount(6, $event->getRequestData());
});

$this->pos->cancel($statusOrder);

$this->assertTrue($this->pos->isSuccess());
$response = $this->pos->getResponse();
$this->assertIsArray($response);
$this->assertNotEmpty($response);
$this->assertTrue($eventIsThrown);
}

public function testGet3DFormData(): void
{
$order = $this->createPaymentOrder();

$eventIsThrown = false;
$this->eventDispatcher->addListener(
RequestDataPreparedEvent::class,
function (RequestDataPreparedEvent $event) use (&$eventIsThrown) {
$eventIsThrown = true;
$this->assertCount(10, $event->getRequestData());
$this->assertSame(PosInterface::TX_TYPE_PAY_AUTH, $event->getTxType());
});
$formData = $this->pos->get3DFormData(
$order,
PosInterface::MODEL_3D_PAY,
PosInterface::TX_TYPE_PAY_AUTH,
$this->card
);

$this->assertCount(5, $formData['inputs']);
$this->assertTrue($eventIsThrown);
}
}
85 changes: 84 additions & 1 deletion tests/Functional/EstV3PosTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,8 @@
namespace Mews\Pos\Tests\Functional;

use Mews\Pos\Entity\Card\CreditCardInterface;
use Mews\Pos\Event\Before3DFormHashCalculatedEvent;
use Mews\Pos\Event\RequestDataPreparedEvent;
use Mews\Pos\Factory\AccountFactory;
use Mews\Pos\Factory\CreditCardFactory;
use Mews\Pos\Factory\PosFactory;
Expand All @@ -19,6 +21,8 @@ class EstV3PosTest extends TestCase
use PaymentTestTrait;

private CreditCardInterface $card;

private EventDispatcher $eventDispatcher;

/** @var PayForPos */
private PosInterface $pos;
Expand All @@ -39,8 +43,10 @@ protected function setUp(): void
PosInterface::MODEL_3D_SECURE,
'TRPS0200',
);
$this->eventDispatcher = new EventDispatcher();

$this->pos = PosFactory::createPosGateway($account, $config, $this->eventDispatcher);

$this->pos = PosFactory::createPosGateway($account, $config, new EventDispatcher());
$this->pos->setTestMode(true);

$this->card = CreditCardFactory::create(
Expand All @@ -58,6 +64,15 @@ public function testNonSecurePaymentSuccess(): array
{
$order = $this->createPaymentOrder();

$eventIsThrown = false;
$this->eventDispatcher->addListener(
RequestDataPreparedEvent::class,
function (RequestDataPreparedEvent $event) use (&$eventIsThrown) {
$eventIsThrown = true;
$this->assertSame(PosInterface::TX_TYPE_PAY_AUTH, $event->getTxType());
$this->assertCount(13, $event->getRequestData());
});

$this->pos->payment(
PosInterface::MODEL_NON_SECURE,
$order,
Expand All @@ -70,6 +85,7 @@ public function testNonSecurePaymentSuccess(): array
$response = $this->pos->getResponse();
$this->assertIsArray($response);
$this->assertNotEmpty($response);
$this->assertTrue($eventIsThrown);

return $this->pos->getResponse();
}
Expand All @@ -81,12 +97,22 @@ public function testStatusSuccess(array $lastResponse): array
{
$statusOrder = $this->createStatusOrder(\get_class($this->pos), $lastResponse);

$eventIsThrown = false;
$this->eventDispatcher->addListener(
RequestDataPreparedEvent::class,
function (RequestDataPreparedEvent $event) use (&$eventIsThrown) {
$eventIsThrown = true;
$this->assertSame(PosInterface::TX_TYPE_STATUS, $event->getTxType());
$this->assertCount(5, $event->getRequestData());
});

$this->pos->status($statusOrder);

$this->assertTrue($this->pos->isSuccess());
$response = $this->pos->getResponse();
$this->assertIsArray($response);
$this->assertNotEmpty($response);
$this->assertTrue($eventIsThrown);

return $lastResponse;
}
Expand All @@ -99,18 +125,37 @@ public function testCancelSuccess(array $lastResponse): void
{
$statusOrder = $this->createCancelOrder(\get_class($this->pos), $lastResponse);

$eventIsThrown = false;
$this->eventDispatcher->addListener(
RequestDataPreparedEvent::class,
function (RequestDataPreparedEvent $event) use (&$eventIsThrown) {
$eventIsThrown = true;
$this->assertSame(PosInterface::TX_TYPE_CANCEL, $event->getTxType());
$this->assertCount(5, $event->getRequestData());
});

$this->pos->cancel($statusOrder);

$this->assertTrue($this->pos->isSuccess());
$response = $this->pos->getResponse();
$this->assertIsArray($response);
$this->assertNotEmpty($response);
$this->assertTrue($eventIsThrown);
}

public function testNonSecurePrePaymentSuccess(): array
{
$order = $this->createPaymentOrder(PosInterface::CURRENCY_TRY, 3);

$eventIsThrown = false;
$this->eventDispatcher->addListener(
RequestDataPreparedEvent::class,
function (RequestDataPreparedEvent $event) use (&$eventIsThrown) {
$eventIsThrown = true;
$this->assertSame(PosInterface::TX_TYPE_PAY_PRE_AUTH, $event->getTxType());
$this->assertCount(13, $event->getRequestData());
});

$this->pos->payment(
PosInterface::MODEL_NON_SECURE,
$order,
Expand All @@ -123,6 +168,7 @@ public function testNonSecurePrePaymentSuccess(): array
$response = $this->pos->getResponse();
$this->assertIsArray($response);
$this->assertNotEmpty($response);
$this->assertTrue($eventIsThrown);

return $this->pos->getResponse();
}
Expand All @@ -134,6 +180,15 @@ public function testNonSecurePostPaymentSuccess(array $lastResponse): void
{
$order = $this->createPostPayOrder(\get_class($this->pos), $lastResponse);

$eventIsThrown = false;
$this->eventDispatcher->addListener(
RequestDataPreparedEvent::class,
function (RequestDataPreparedEvent $event) use (&$eventIsThrown) {
$eventIsThrown = true;
$this->assertSame(PosInterface::TX_TYPE_PAY_POST_AUTH, $event->getTxType());
$this->assertCount(5, $event->getRequestData());
});

$this->pos->payment(
PosInterface::MODEL_NON_SECURE,
$order,
Expand All @@ -144,5 +199,33 @@ public function testNonSecurePostPaymentSuccess(array $lastResponse): void
$response = $this->pos->getResponse();
$this->assertIsArray($response);
$this->assertNotEmpty($response);
$this->assertTrue($eventIsThrown);
}

public function testGet3DFormData(): void
{
$order = $this->createPaymentOrder();

$eventIsThrown = false;
$this->eventDispatcher->addListener(
Before3DFormHashCalculatedEvent::class,
function (Before3DFormHashCalculatedEvent $event) use (&$eventIsThrown) {
$eventIsThrown = true;
$this->assertCount(17, $event->getFormInputs());
$this->assertSame(PosInterface::TX_TYPE_PAY_AUTH, $event->getTxType());
$formInputs = $event->getFormInputs();
$formInputs['test_input'] = 'test_value';
$event->setFormInputs($formInputs);
});

$formData = $this->pos->get3DFormData(
$order,
PosInterface::MODEL_3D_PAY,
PosInterface::TX_TYPE_PAY_AUTH,
$this->card
);
$this->assertCount(19, $formData['inputs']);
$this->assertArrayHasKey('test_input', $formData['inputs']);
$this->assertTrue($eventIsThrown);
}
}
Loading

0 comments on commit 53caeb4

Please sign in to comment.