Created
February 8, 2023 08:05
-
-
Save denrad/f4239430f64b4e04c497f6ecb1640742 to your computer and use it in GitHub Desktop.
a1
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| <?php | |
| namespace tests\common\integration\drivers\paymentsystems\monetix; | |
| use common\drivers\paymentsystems\monetix\exceptions\MonetixException; | |
| use domain\exceptions\MutexException; | |
| use domain\mutex\interfaces\TransactionBatchMutex; | |
| use domain\transactions\business_scheme\processes\ProcessesFlow; | |
| use domain\transactions\interfaces\{ | |
| PayinTransaction, | |
| PayinTransactionRepository | |
| }; | |
| use tests\components\IntegrationTestCase; | |
| use common\drivers\paymentsystems\monetix\CallbackHandler; | |
| class CallbackHandlerTest extends IntegrationTestCase | |
| { | |
| private TransactionBatchMutex $mutex; | |
| private PayinTransactionRepository $transactionRepository; | |
| private ProcessesFlow $processFlow; | |
| private Callbackhandler $handler; | |
| public function testHandleWrongStatus(): void | |
| { | |
| $request = [ | |
| 'payment' => [ | |
| 'status' => '::wrong status::', | |
| ], | |
| ]; | |
| $transactionId = random_int(1, 1000); | |
| $this->transactionRepository | |
| ->expects(self::never()) | |
| ->method('findById'); | |
| $this->handler->handle($request, $transactionId); | |
| } | |
| public function testHandleTransactionNotFound(): void | |
| { | |
| $request = [ | |
| 'payment' => [ | |
| 'status' => 'success', | |
| ], | |
| ]; | |
| $transactionId = random_int(1, 1000); | |
| $this->transactionRepository | |
| ->expects(self::once()) | |
| ->method('findById') | |
| ->with($transactionId) | |
| ->willReturn(null); | |
| self::expectException(MonetixException::class); | |
| self::expectExceptionMessage('Transaction with id ' . $transactionId . ' not found'); | |
| $this->handler->handle($request, $transactionId); | |
| } | |
| public function testHandleMutexNotWork(): void | |
| { | |
| $transactionId = random_int(1, 1000); | |
| $this->mutex->expects(self::once()) | |
| ->method('acquire') | |
| ->willThrowException( | |
| new MutexException('Can\'t acquire transaction locking. Transaction id: ' . $transactionId . '.') | |
| ); | |
| $payinTransaction = $this->createMock(PayinTransaction::class); | |
| // $payinTransaction | |
| // ->expects(self::once()) | |
| // ->method('getStatus') | |
| // ->willReturn(\domain\transactions\Transaction::STATUS_PENDING); | |
| $this->transactionRepository | |
| ->expects(self::once()) | |
| ->method('findById') | |
| ->with($transactionId) | |
| ->willReturn($payinTransaction); | |
| $this->handler->handle([ | |
| 'payment' => [ | |
| 'status' => 'success', | |
| ], | |
| ], | |
| $transactionId | |
| ); | |
| } | |
| public function testHandleSuccessStatus(): void | |
| { | |
| $request = [ | |
| 'payment' => [ | |
| 'status' => 'success', | |
| ], | |
| ]; | |
| $transactionId = random_int(1, 1000); | |
| $this->handler->handle($request, $transactionId); | |
| } | |
| public function testHandleFailStatus(): void | |
| { | |
| } | |
| protected function setUp(): void | |
| { | |
| parent::setUp(); | |
| $this->mutex = $this->createMock(TransactionBatchMutex::class); | |
| $this->transactionRepository = $this->createMock(PayinTransactionRepository::class); | |
| $this->processFlow = $this->createMock(ProcessesFlow::class); | |
| $this->handler = new CallbackHandler( | |
| $this->transactionRepository, | |
| $this->mutex, | |
| $this->processFlow | |
| ); | |
| } | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment