Magento 2 Documentation  2.3
Documentation for Magento 2 CMS v2.3 (December 2018)
TransactionIdHandlerTest.php
Go to the documentation of this file.
1 <?php
7 
12 
13 class TransactionIdHandlerTest extends \PHPUnit\Framework\TestCase
14 {
15  public function testHandle()
16  {
17  $paymentDO = $this->createMock(PaymentDataObjectInterface::class);
18  $paymentInfo = $this->getMockBuilder(Payment::class)
19  ->disableOriginalConstructor()
20  ->getMock();
21  $handlingSubject = [
22  'payment' => $paymentDO
23  ];
24 
25  $transaction = \Braintree\Transaction::factory(['id' => 1]);
26  $response = [
27  'object' => new \Braintree\Result\Successful($transaction, 'transaction')
28  ];
29 
30  $subjectReader = $this->getMockBuilder(SubjectReader::class)
31  ->disableOriginalConstructor()
32  ->getMock();
33 
34  $subjectReader->expects(static::once())
35  ->method('readPayment')
36  ->with($handlingSubject)
37  ->willReturn($paymentDO);
38  $paymentDO->expects(static::atLeastOnce())
39  ->method('getPayment')
40  ->willReturn($paymentInfo);
41  $subjectReader->expects(static::once())
42  ->method('readTransaction')
43  ->with($response)
44  ->willReturn($transaction);
45 
46  $paymentInfo->expects(static::once())
47  ->method('setTransactionId')
48  ->with(1);
49 
50  $paymentInfo->expects(static::once())
51  ->method('setIsTransactionClosed')
52  ->with(false);
53  $paymentInfo->expects(static::once())
54  ->method('setShouldCloseParentTransaction')
55  ->with(false);
56 
57  $handler = new TransactionIdHandler($subjectReader);
58  $handler->handle($handlingSubject, $response);
59  }
60 }
$transaction
$response
Definition: 404.php:11
$paymentInfo
catch(\Exception $e) $handler
Definition: index.php:30