Magento 2 Documentation  2.3
Documentation for Magento 2 CMS v2.3 (December 2018)
PayPalDetailsHandlerTest.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 PayPalDetailsHandlerTest extends \PHPUnit\Framework\TestCase
19 {
23  private $payPalHandler;
24 
28  private $paymentMock;
29 
33  private $subjectReaderMock;
34 
35  protected function setUp()
36  {
37  $this->paymentMock = $this->getMockBuilder(Payment::class)
38  ->disableOriginalConstructor()
39  ->setMethods([
40  'setAdditionalInformation',
41  ])
42  ->getMock();
43  $this->subjectReaderMock = $this->getMockBuilder(SubjectReader::class)
44  ->disableOriginalConstructor()
45  ->getMock();
46 
47  $this->payPalHandler = new PayPalDetailsHandler($this->subjectReaderMock);
48  }
49 
53  public function testHandle()
54  {
55  $paymentDataMock = $this->getPaymentDataObjectMock();
56  $transaction = $this->getBraintreeTransaction();
57 
58  $subject = ['payment' => $paymentDataMock];
59  $response = ['object' => $transaction];
60 
61  $this->subjectReaderMock->expects(self::once())
62  ->method('readPayment')
63  ->with($subject)
64  ->willReturn($paymentDataMock);
65  $this->subjectReaderMock->expects(self::once())
66  ->method('readTransaction')
67  ->with($response)
68  ->willReturn($transaction);
69  $this->subjectReaderMock->expects(static::once())
70  ->method('readPayPal')
71  ->with($transaction)
72  ->willReturn($transaction->paypal);
73 
74  $this->paymentMock->expects(static::exactly(2))
75  ->method('setAdditionalInformation');
76 
77  $this->payPalHandler->handle($subject, $response);
78  }
79 
84  private function getPaymentDataObjectMock()
85  {
86  $mock = $this->getMockBuilder(PaymentDataObject::class)
87  ->setMethods(['getPayment'])
88  ->disableOriginalConstructor()
89  ->getMock();
90 
91  $mock->expects(static::once())
92  ->method('getPayment')
93  ->willReturn($this->paymentMock);
94 
95  return $mock;
96  }
97 
102  private function getBraintreeTransaction()
103  {
104  $attributes = [
105  'id' => '23ui8be',
106  'paypal' => [
107  'paymentId' => 'u239dkv6n2lds',
108  'payerEmail' => '[email protected]'
109  ]
110  ];
111 
112  $transaction = Transaction::factory($attributes);
113 
114  return $transaction;
115  }
116 }
$transaction
$response
Definition: 404.php:11
$attributes
Definition: matrix.phtml:13