From 53caeb4841ef455f516d98bb1f309e207307cc4e Mon Sep 17 00:00:00 2001 From: Nuryagdy Mustapayev Date: Tue, 26 Dec 2023 19:10:12 +0100 Subject: [PATCH] test - added event examples into functional tests --- tests/Functional/AkOdePosTest.php | 46 +++++++++++++++- tests/Functional/EstV3PosTest.php | 85 ++++++++++++++++++++++++++++- tests/Functional/GarantiPosTest.php | 83 +++++++++++++++++++++++++++- tests/Functional/PayForPosTest.php | 84 +++++++++++++++++++++++++++- 4 files changed, 293 insertions(+), 5 deletions(-) diff --git a/tests/Functional/AkOdePosTest.php b/tests/Functional/AkOdePosTest.php index 882bd33f..d2dc4794 100644 --- a/tests/Functional/AkOdePosTest.php +++ b/tests/Functional/AkOdePosTest.php @@ -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; @@ -19,6 +20,8 @@ class AkOdePosTest extends TestCase use PaymentTestTrait; private CreditCardInterface $card; + + private EventDispatcher $eventDispatcher; /** @var AkOdePos */ private PosInterface $pos; @@ -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( @@ -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, @@ -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(); } @@ -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; } @@ -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); } } diff --git a/tests/Functional/EstV3PosTest.php b/tests/Functional/EstV3PosTest.php index 3433d233..dea42e0b 100644 --- a/tests/Functional/EstV3PosTest.php +++ b/tests/Functional/EstV3PosTest.php @@ -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; @@ -19,6 +21,8 @@ class EstV3PosTest extends TestCase use PaymentTestTrait; private CreditCardInterface $card; + + private EventDispatcher $eventDispatcher; /** @var PayForPos */ private PosInterface $pos; @@ -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( @@ -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, @@ -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(); } @@ -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; } @@ -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, @@ -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(); } @@ -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, @@ -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); } } diff --git a/tests/Functional/GarantiPosTest.php b/tests/Functional/GarantiPosTest.php index 882faece..03a92105 100644 --- a/tests/Functional/GarantiPosTest.php +++ b/tests/Functional/GarantiPosTest.php @@ -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; @@ -19,6 +21,8 @@ class GarantiPosTest extends TestCase use PaymentTestTrait; private CreditCardInterface $card; + + private EventDispatcher $eventDispatcher; /** @var GarantiPos */ private PosInterface $pos; @@ -43,7 +47,9 @@ protected function setUp(): void '123qweASD/' ); - $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( @@ -61,6 +67,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(7, $event->getRequestData()); + }); + $this->pos->payment( PosInterface::MODEL_NON_SECURE, $order, @@ -84,6 +99,15 @@ 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()); @@ -102,18 +126,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(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 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(7, $event->getRequestData()); + }); + $this->pos->payment( PosInterface::MODEL_NON_SECURE, $order, @@ -126,6 +169,7 @@ public function testNonSecurePrePaymentSuccess(): array $response = $this->pos->getResponse(); $this->assertIsArray($response); $this->assertNotEmpty($response); + $this->assertTrue($eventIsThrown); return $this->pos->getResponse(); } @@ -137,6 +181,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(6, $event->getRequestData()); + }); + $this->pos->payment( PosInterface::MODEL_NON_SECURE, $order, @@ -147,5 +200,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(19, $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(21, $formData['inputs']); + $this->assertArrayHasKey('test_input', $formData['inputs']); + $this->assertTrue($eventIsThrown); } } diff --git a/tests/Functional/PayForPosTest.php b/tests/Functional/PayForPosTest.php index 49d18538..9973f694 100644 --- a/tests/Functional/PayForPosTest.php +++ b/tests/Functional/PayForPosTest.php @@ -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; @@ -19,6 +21,8 @@ class PayForPosTest extends TestCase use PaymentTestTrait; private CreditCardInterface $card; + + private EventDispatcher $eventDispatcher; /** @var PayForPos */ private PosInterface $pos; @@ -39,8 +43,9 @@ protected function setUp(): void PosInterface::MODEL_3D_SECURE, '12345678' ); + $this->eventDispatcher = new EventDispatcher(); - $this->pos = PosFactory::createPosGateway($account, $config, new EventDispatcher()); + $this->pos = PosFactory::createPosGateway($account, $config, $this->eventDispatcher); $this->pos->setTestMode(true); $this->card = CreditCardFactory::create( @@ -58,6 +63,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(16, $event->getRequestData()); + }); + $this->pos->payment( PosInterface::MODEL_NON_SECURE, $order, @@ -70,6 +84,7 @@ public function testNonSecurePaymentSuccess(): array $response = $this->pos->getResponse(); $this->assertIsArray($response); $this->assertNotEmpty($response); + $this->assertTrue($eventIsThrown); return $this->pos->getResponse(); } @@ -81,12 +96,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(8, $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; } @@ -99,12 +124,22 @@ 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(9, $event->getRequestData()); + }); + $this->pos->cancel($statusOrder); $this->assertTrue($this->pos->isSuccess()); $response = $this->pos->getResponse(); $this->assertIsArray($response); $this->assertNotEmpty($response); + $this->assertTrue($eventIsThrown); } @@ -112,6 +147,15 @@ 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(16, $event->getRequestData()); + }); + $this->pos->payment( PosInterface::MODEL_NON_SECURE, $order, @@ -124,6 +168,7 @@ public function testNonSecurePrePaymentSuccess(): array $response = $this->pos->getResponse(); $this->assertIsArray($response); $this->assertNotEmpty($response); + $this->assertTrue($eventIsThrown); return $this->pos->getResponse(); } @@ -135,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(10, $event->getRequestData()); + }); + $this->pos->payment( PosInterface::MODEL_NON_SECURE, $order, @@ -145,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); } }