Magento 2 Documentation  2.3
Documentation for Magento 2 CMS v2.3 (December 2018)
ThreeDSecureDetailsHandlerTest.php
Go to the documentation of this file.
1 <?php
7 
8 use Braintree\Transaction;
13 use PHPUnit_Framework_MockObject_MockObject as MockObject;
14 
18 class ThreeDSecureDetailsHandlerTest extends \PHPUnit\Framework\TestCase
19 {
20 
21  const TRANSACTION_ID = '432er5ww3e';
22 
26  private $handler;
27 
31  private $paymentMock;
32 
36  private $subjectReaderMock;
37 
38  protected function setUp()
39  {
40  $this->paymentMock = $this->getMockBuilder(Payment::class)
41  ->disableOriginalConstructor()
42  ->setMethods([
43  'unsAdditionalInformation',
44  'hasAdditionalInformation',
45  'setAdditionalInformation',
46  ])
47  ->getMock();
48 
49  $this->subjectReaderMock = $this->getMockBuilder(SubjectReader::class)
50  ->disableOriginalConstructor()
51  ->getMock();
52 
53  $this->handler = new ThreeDSecureDetailsHandler($this->subjectReaderMock);
54  }
55 
59  public function testHandle()
60  {
61  $paymentData = $this->getPaymentDataObjectMock();
62  $transaction = $this->getBraintreeTransaction();
63 
64  $subject = ['payment' => $paymentData];
65  $response = ['object' => $transaction];
66 
67  $this->subjectReaderMock->expects(self::once())
68  ->method('readPayment')
69  ->with($subject)
70  ->willReturn($paymentData);
71  $this->subjectReaderMock->expects(self::once())
72  ->method('readTransaction')
73  ->with($response)
74  ->willReturn($transaction);
75 
76  $this->paymentMock->expects(static::at(1))
77  ->method('setAdditionalInformation')
78  ->with('liabilityShifted', 'Yes');
79  $this->paymentMock->expects(static::at(2))
80  ->method('setAdditionalInformation')
81  ->with('liabilityShiftPossible', 'Yes');
82 
83  $this->handler->handle($subject, $response);
84  }
85 
90  private function getPaymentDataObjectMock()
91  {
92  $mock = $this->getMockBuilder(PaymentDataObject::class)
93  ->setMethods(['getPayment'])
94  ->disableOriginalConstructor()
95  ->getMock();
96 
97  $mock->expects(static::once())
98  ->method('getPayment')
99  ->willReturn($this->paymentMock);
100 
101  return $mock;
102  }
103 
108  private function getBraintreeTransaction()
109  {
110  $attributes = [
111  'id' => self::TRANSACTION_ID,
112  'threeDSecureInfo' => $this->getThreeDSecureInfo()
113  ];
114 
115  $transaction = Transaction::factory($attributes);
116 
117  return $transaction;
118  }
119 
124  private function getThreeDSecureInfo()
125  {
126  $attributes = [
127  'liabilityShifted' => 'Yes',
128  'liabilityShiftPossible' => 'Yes'
129  ];
130 
131  return $attributes;
132  }
133 }
$transaction
$response
Definition: 404.php:11
$attributes
Definition: matrix.phtml:13